Re: [GENERAL] Count column with name 'count' returns multiple rows.Why? - Mailing list pgsql-general

From Peter J. Holzer
Subject Re: [GENERAL] Count column with name 'count' returns multiple rows.Why?
Date
Msg-id 20170818204737.GA8487@hjp.at
Whole thread Raw
In response to Re: [GENERAL] Count column with name 'count' returns multiple rows.Why?  (Justin Pryzby <pryzby@telsasoft.com>)
Responses Re: [GENERAL] Count column with name 'count' returns multiple rows.Why?  (Justin Pryzby <pryzby@telsasoft.com>)
Re: [GENERAL] Count column with name 'count' returns multiple rows. Why?  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general
On 2017-08-18 06:37:15 -0500, Justin Pryzby wrote:
> On Fri, Aug 18, 2017 at 01:01:45PM +0200, Rob Audenaerde wrote:
> > I don't understand why this query:
> >
> >    select count(base.*) from mytable base;
> >
> > does return multiple rows.
> >
> >    select count(1) from mytable base;
> >
> > returns the proper count.
> >
> > There is a column with the name 'count'.
> >
> > Can anyone please explain this behaviour?
>
> https://www.postgresql.org/docs/9.6/static/sql-expressions.html#SQL-EXPRESSIONS-FUNCTION-CALLS
> https://www.postgresql.org/docs/9.6/static/rowtypes.html#ROWTYPES-USAGE

Maybe I overlooked it, but I don't see anything in those pages which
explains why «count» is parsed as a column name in the first example and
as a function name in the second.

Nor do I see what «count(base.*)» is supposed to mean. It seems to be
completely equivalent to just writing «count», but the part in
parentheses is not ignored: It has to be either the table name or the
table name followed by «.*». Everything else I tried either led to a
syntax error or to «count» being recognized as a function. So apparently
columnname open-parenthesis tablename closed-parenthesis is a specific
syntactic construct, but I can't find it documented anywhere.

        hp

--
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp@hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>

Attachment

pgsql-general by date:

Previous
From: twoflower
Date:
Subject: Re: [GENERAL] archive_command fails but works outside of Postgres
Next
From: Justin Pryzby
Date:
Subject: Re: [GENERAL] Count column with name 'count' returns multiple rows.Why?