Revision 4475
Added by Aaron Marcuse-Kubitza about 12 years ago
schemas/functions.sql | ||
---|---|---|
138 | 138 |
|
139 | 139 |
|
140 | 140 |
-- |
141 |
-- Name: _nullIf(text, text, datatype); Type: FUNCTION; Schema: functions; Owner: -
|
|
141 |
-- Name: _nullIf(anyelement, text, datatype); Type: FUNCTION; Schema: functions; Owner: -
|
|
142 | 142 |
-- |
143 | 143 |
|
144 |
CREATE FUNCTION "_nullIf"(value text, "null" text, type datatype DEFAULT 'str'::datatype) RETURNS text
|
|
144 |
CREATE FUNCTION "_nullIf"(value anyelement, "null" text, type datatype DEFAULT 'str'::datatype) RETURNS anyelement
|
|
145 | 145 |
LANGUAGE plpgsql IMMUTABLE |
146 | 146 |
AS $$ |
147 | 147 |
DECLARE |
148 | 148 |
"null" text NOT NULL := "null"; -- add NOT NULL |
149 | 149 |
type functions.datatype NOT NULL := type; -- add NOT NULL |
150 | 150 |
BEGIN |
151 |
IF type = 'str' THEN RETURN nullif(value, "null"); -- no cast needed
|
|
151 |
IF type = 'str' THEN RETURN nullif(value::text, "null");
|
|
152 | 152 |
-- Invalid value is ignored, but invalid null value generates error |
153 | 153 |
ELSIF type = 'float' THEN |
154 | 154 |
DECLARE |
Also available in: Unified diff
schemas/functions.sql: _nullIf(): Polymorphically support other datatypes besides text