Re: Subquery uses ungrouped column

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Subquery uses ungrouped column
Date: 2016-05-26 16:55:30
Message-ID: 9544.1464281730@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> From observation PostgreSQL doesn't recognize the equivalency of the
> outer "group by substring(fileid from -1)" and the subquery expression.

Well, it would without the subselect in between. There's a code comment
in parse_agg.c about this:

* NOTE: we recognize grouping expressions in the main query, but only
* grouping Vars in subqueries. For example, this will be rejected,
* although it could be allowed:
* SELECT
* (SELECT x FROM bar where y = (foo.a + foo.b))
* FROM foo
* GROUP BY a + b;
* The difficulty is the need to account for different sublevels_up.
* This appears to require a whole custom version of equal(), which is
* way more pain than the feature seems worth.

It'd probably be possible to fix parse_agg.c if you didn't mind expending
lots of cycles on such cases. I'm not sure offhand whether there would
be implications in the planner, or what it would take to fix them if so.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Grittner 2016-05-26 18:31:27 Re: full text search index
Previous Message Tom Lane 2016-05-26 16:44:51 Re: [GENERAL] Permission Denied Error on pg_xlog/RECOVERYXLOG file