Re: select count(*);

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: select count(*);
Дата
Msg-id 17995.1434032828@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: select count(*);  (Marc Mamin <M.Mamin@intershop.de>)
Список pgsql-general
Marc Mamin <M.Mamin@intershop.de> writes:
>> The * might be a bit tricky, though,
>> since 'select *;' doesn't work.

> That's the point. * has no meaning without FROM

PG regards "count(*)" as a weird spelling of "count()", ie, invoke an
aggregate that takes no arguments.  It really doesn't have anything to do
with the meaning of "*" as a SELECT-list item, any more than it does with
the meaning of "*" as multiplication, say.  It's just syntax that's
written like that because the SQL standard says we have to.

Another way of making the point is that SELECT without a FROM list can
be seen as implicitly selecting from a dummy table with one row and no
columns.  Some other systems such as Oracle make you do that explicitly,
ie the infamous "FROM dual" hack; there's nothing in the SQL standard
saying you can omit FROM.  If you suppose that that's the underlying model
then the result of "select count(*)" is completely natural.

            regards, tom lane


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

Предыдущее
От: Geoff Winkless
Дата:
Сообщение: Re: select count(*);
Следующее
От: "Charles Clavadetscher"
Дата:
Сообщение: Re: Prevent roles not having admin option from granting themselves to other roles