Re: parser oddity (t.count) - Mailing list pgsql-hackers

From Tom Lane
Subject Re: parser oddity (t.count)
Date
Msg-id 23194.959272120@sss.pgh.pa.us
Whole thread Raw
In response to parser oddity (t.count)  (Ed Loehr <eloehr@austin.rr.com>)
Responses Re: parser oddity (t.count)  (Andreas Zeugswetter <andreas.zeugswetter@telecom.at>)
List pgsql-hackers
Ed Loehr <eloehr@austin.rr.com> writes:
> insert into foo (id, h_count) select t.id, t.count from temp_foo t;

> ERROR:  Attribute t.id must be GROUPed or used in an aggregate function

> I mislabeled the 't.h_count' column in my INSERT statement as 't.count',
> and what I found strange was that the parser evidently thinks t.count is
> an aggregate.  Is 't.count' valid use/syntax for an aggregate?

Hmm.  Due to some ancient Postquel features that you probably don't want
to hear about, foo.bar and bar(foo) are considered near-equivalent
notations by the parser.  It looks like when it couldn't find 'count' as
a field name, it tried and succeeded to interpret it as a function call
instead.

(A contributing problem here is that the parser is absolutely lax about
what it will take as the argument of count().  IMHO you should have
gotten something like "Unable to select an aggregate function
count(unknown)", which might have been a little less confusing.)

It works in the other direction too: field(foo) will be interpreted as
foo.field if foo has a column named field.

This equivalence can be pretty confusing if you don't know about it, but
I'm hesitant to suggest ripping it out because of the risk of breaking
old applications.  Anyone have strong opinions one way or the other?
        regards, tom lane


pgsql-hackers by date:

Previous
From: Zeugswetter Andreas SB
Date:
Subject: AW: AW: AW: More Performance
Next
From: Tom Lane
Date:
Subject: Re: Create user/create database outside template1