Re: select count(*);

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
Cc: "'Chris Mair'" <chris(at)1006(dot)org>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: select count(*);
Date: 2015-06-11 14:27:08
Message-ID: 17995.1434032828@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Marc Mamin <M(dot)Mamin(at)intershop(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Charles Clavadetscher 2015-06-11 14:27:44 Re: Prevent roles not having admin option from granting themselves to other roles
Previous Message Geoff Winkless 2015-06-11 14:20:43 Re: select count(*);