Pavel Stehule <pavel.steh...@gmail.com> writes: > next related example
> CREATE OR REPLACE FUNCTION public.myleast(VARIADIC integer[]) > RETURNS integer > LANGUAGE sql > AS $function$ > select min(v) from unnest($1) g(v) > $function$ The reason you get a null from that is that (1) unnest() produces zero rows out for either a null or empty-array input, and (2) min() over zero rows produces NULL. In a lot of cases, it's not very sane for aggregates over no rows to produce NULL; the best-known example is that SUM() produces NULL, when anyone who'd not suffered brain-damage from sitting on the SQL committee would have made it return zero. So I'm not very comfortable with generalizing from this specific case to decide that NULL is the universally right result. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers