Re: count(*) of zero rows returns 1

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: count(*) of zero rows returns 1
Дата
Msg-id 12414.1358113408@sss.pgh.pa.us
обсуждение исходный текст
Ответ на count(*) of zero rows returns 1  (Gurjeet Singh <singh.gurjeet@gmail.com>)
Ответы Re: count(*) of zero rows returns 1  (Gurjeet Singh <singh.gurjeet@gmail.com>)
Re: count(*) of zero rows returns 1  (David Johnston <polobo@yahoo.com>)
Список pgsql-hackers
Gurjeet Singh <singh.gurjeet@gmail.com> writes:
> Can somebody explain why a standalone count(*) returns 1?
> postgres=# select count(*);
>  count
> -------
>      1
> (1 row)

The Oracle equivalent of that would be "SELECT count(*) FROM dual".
Does it make more sense to you thought of that way?

> I agree it's an odd thing for someone to query, but I feel it should return
> 0, and not 1.

For that to return zero, it would also be necessary for "SELECT 2+2"
to return zero rows.  Which would be consistent with some views of the
universe, but not particularly useful.  Another counterexample is

regression=# select sum(42);sum 
----- 42
(1 row)

which by your argument would need to return NULL, since that would be
SUM's result over zero rows.
        regards, tom lane



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: erroneous restore into pg_catalog schema
Следующее
От: Marko Kreen
Дата:
Сообщение: Re: pgcrypto seeding problem when ssl=on