How to use mixed int and numeric arguments in a Postgres 9.1+ function
问题 I'm looking for a way to create an icase() function which works with any second and third parameter compatible data types. I tried in Postgres 9.4: CREATE OR REPLACE FUNCTION public.icase( cond1 boolean, res1 anyelement, conddefault anyelement) RETURNS anyelement AS ' SELECT CASE WHEN $1 THEN $2 ELSE $3 END; ' LANGUAGE sql IMMUTABLE; But: select icase( true, 1.0, 0 ) causes error: ERROR: function icase(boolean, numeric, integer) does not exist LINE 9: select icase( true, 1.0, 0 ) ^ HINT: No