Re: proposal: fix corner use case of variadic fuctions usage

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: proposal: fix corner use case of variadic fuctions usage
Дата
Msg-id 21285.1358960284@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: proposal: fix corner use case of variadic fuctions usage  (Pavel Stehule <pavel.stehule@gmail.com>)
Ответы Re: proposal: fix corner use case of variadic fuctions usage  (Pavel Stehule <pavel.stehule@gmail.com>)
Список pgsql-hackers
Pavel Stehule <pavel.stehule@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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: Prepared statements fail after schema changes with surprising error
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: [COMMITTERS] pgsql: Improve concurrency of foreign key locking