Re: Strange error message when reference non-existent column foo."count"

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Patrick Krecker <patrick(at)judicata(dot)com>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Strange error message when reference non-existent column foo."count"
Date: 2014-12-17 23:06:16
Message-ID: 32098.1418857576@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Patrick Krecker <patrick(at)judicata(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G Johnston 2014-12-17 23:11:49 Re: Strange error message when reference non-existent column foo."count"
Previous Message Patrick Krecker 2014-12-17 22:53:40 Re: Strange error message when reference non-existent column foo."count"