Re: 7.0.3 and 7.1.3 different results?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: 7.0.3 and 7.1.3 different results?
Дата
Msg-id 8826.1002034571@sss.pgh.pa.us
обсуждение исходный текст
Ответ на 7.0.3 and 7.1.3 different results?  (Joel Mc Graw <jpmcgraw1@home.com>)
Список pgsql-sql
Joel Mc Graw <jpmcgraw1@home.com> writes:
> A query such as "select sum(pages) from job_documents where
> delivery_type='print'" returned 0 in version 7.0.3 if there were no rows
> matching the query.  In 7.1.3 the result is NULL if no rows match the
> query.  Why the change?  Which result is "correct" according to the SQL
> standard?

NULL is correct according to the SQL standard (yes, I think it's
brain-dead too).  SQL92 section 6.5 saith:
           b) If AVG, MAX, MIN, or SUM is specified, then
             Case:
             i) If TXA is empty, then the result is the null value.
--------------------------------------------------
            ii) If AVG is specified, then the result is the average of the                values in TXA.
           iii) If MAX or MIN is specified, then the result is respec-                tively the maximum or minimum
valuein TXA. These results                are determined using the comparison rules specified in
Subclause8.2, "<comparison predicate>".
 
            iv) If SUM is specified, then the result is the sum of the                values in TXA. If the sum is not
withinthe range of the                data type of the result, then an exception condition is                raised:
dataexception-numeric value out of range.
 

I'd suggest COALESCE(SUM(foo), 0) if you need a zero result.

However, I dispute your assertion that 7.0.3 returned zero.  I just
double checked, and I get a NULL there too.  If we ever returned zero,
it was a long time ago.
        regards, tom lane


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

Предыдущее
От: domingo@dad-it.com (Domingo Alvarez Duarte)
Дата:
Сообщение: Re: A bug in triggers PG 7.1.3 or misunderstand ?
Следующее
От: "Michael Remme"
Дата:
Сообщение: Re: TEXT in select