Re: Strange error message when reference non-existent column foo."count" - Mailing list pgsql-general

From Tom Lane
Subject Re: Strange error message when reference non-existent column foo."count"
Date
Msg-id 32098.1418857576@sss.pgh.pa.us
Whole thread Raw
In response to Strange error message when reference non-existent column foo."count"  (Patrick Krecker <patrick@judicata.com>)
List pgsql-general
Patrick Krecker <patrick@judicata.com> writes:
> As expected, the following fails:

> select count from foo;
> ERROR:  column "count" does not exist
> LINE 1: select count from foo;
>                ^
> But if I change the syntax to something I thought was equivalent:

> select foo."count" from foo;
>  count
> -------
>      3
> (1 row)

> It works! This was quite surprising to me. Is this expected behavior,

Yes.  foo.bar is equivalent to bar(foo) in Postgres.  It is documented;
see for instance the Note here:
http://www.postgresql.org/docs/9.3/static/sql-expressions.html#SQL-EXPRESSIONS-FUNCTION-CALLS

> that
> you can call an aggregate function without any parentheses (I can't find
> any other syntax that works for count() sans parentheses, and this behavior
> doesn't occur for any other aggregate)?

It occurs for any function at all, aggregate or otherwise, if the function
can accept the table's composite type as argument.  The alternatives you
tried probably were not things that could take a composite-type argument.
count() is pretty lax about what it will take, since it only cares about
is-null-or-not.

            regards, tom lane


pgsql-general by date:

Previous
From: Patrick Krecker
Date:
Subject: Re: Strange error message when reference non-existent column foo."count"
Next
From: David G Johnston
Date:
Subject: Re: Strange error message when reference non-existent column foo."count"