Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T4JAy-0002zh-Cx for pgsql-bugs@postgresql.org; Wed, 22 Aug 2012 22:13:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T4JAu-0008Fx-AV for pgsql-bugs@postgresql.org; Wed, 22 Aug 2012 22:13:23 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q7MMDI4B023840; Wed, 22 Aug 2012 18:13:18 -0400 (EDT) From: Tom Lane To: Chris Travers cc: pgsql-bugs@postgresql.org Subject: Re: GROUP BY checks inadequate when set returning functions in column list In-reply-to: References: <15650.1345647879@sss.pgh.pa.us> Comments: In-reply-to Chris Travers message dated "Wed, 22 Aug 2012 08:20:31 -0700" Date: Wed, 22 Aug 2012 18:13:18 -0400 Message-ID: <23839.1345673598@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) X-Archive-Number: 201208/167 X-Sequence-Number: 33891 Chris Travers writes: > On Wed, Aug 22, 2012 at 8:04 AM, Tom Lane wrote: >> Chris Travers writes: > mtech_test=# explain analyze select (account_heading__list()).* group by accno >> Hm, that really ought to throw an error, since you have ungrouped >> columns in the result. Not sure why it doesn't. > Yeah, that was my point. I don't know if it is worth fixing but > always better to report. I looked into this, and found that the query basically expands to SELECT (func()).field1, (func()).field2, (func()).field3, ... GROUP BY 2; There are no Vars in this query; only FuncExprs and FieldSelects. So that's why the check for ungrouped variables isn't complaining. To make it complain, we'd have to have a notion that the different occurrences of the function are generating related columns of a row, which is something that quite disappears in the *-expansion. As I said before, this isn't really an area that anybody is excited about changing --- it's all legacy behavior, and if we change it we're more likely to get complaints from people whose code broke than compliments from people who can now use it for something. Eventually I think SRFs in the targetlist will be deprecated in favor of LATERAL constructs, though it will be a very long time before we could consider removing the feature altogether. regards, tom lane