Re: PL/PGSQL question

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: PL/PGSQL question
Дата
Msg-id 5096.1042784448@sss.pgh.pa.us
обсуждение исходный текст
Ответ на PL/PGSQL question  (Jean-Christian Imbeault <jc@mega-bucks.co.jp>)
Список pgsql-general
Jean-Christian Imbeault <jc@mega-bucks.co.jp> writes:
> I wrote the following plpgsql function. The problem I have is that if no
> rows are found my function returns NULL whereas it should be returning 0.

SUM() over no rows returns NULL, not zero, per the SQL spec.
(Yes, it's a stupid spec.)

Your IF NOT FOUND test can never succeed, because the select will always
return exactly one row no matter what.  Try testing total_sales for NULL
instead.

            regards, tom lane

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

Предыдущее
От: Jean-Christian Imbeault
Дата:
Сообщение: PL/PGSQL question
Следующее
От: Jean-Christian Imbeault
Дата:
Сообщение: Re: PL/PGSQL question