Re: PostgreSQL query with FULL OUTER JOIN and subquery using column of GROUP BY expression ERROR: subquery uses ungrouped column from outer query - Mailing list pgsql-general

From David G. Johnston
Subject Re: PostgreSQL query with FULL OUTER JOIN and subquery using column of GROUP BY expression ERROR: subquery uses ungrouped column from outer query
Date
Msg-id CAKFQuwY27TZSERWdmC+=RO+B86KAOSW+CeJSSL52eUZQLYZsrA@mail.gmail.com
Whole thread Raw
In response to Re: PostgreSQL query with FULL OUTER JOIN and subquery using column of GROUP BY expression ERROR: subquery uses ungrouped column from outer query  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: PostgreSQL query with FULL OUTER JOIN and subquery using column of GROUP BY expression ERROR: subquery uses ungrouped column from outer query
List pgsql-general
On Wed, Feb 25, 2026 at 9:00 AM Adrian Klaver <adrian.klaver@aklaver.com> wrote:
1) Why FROM (SELECT * FROM t1 ) AS t1 instead of just FROM t1?
    Same for JOIN (SELECT * FROM t3   ) t3

Seems immaterial.  It's just a consequence of simplifying the original problem query. If it is consequential that would seem buggy.


2) Why are the field names not table qualified e.g. t2.id, t3.id, etc?

Because of the USING clause, those references shouldn't exist in the main query.


3) What is the desired outcome?

For the engine to realize the 'id' in the group by and the 'id' in the scalar subquery are the same 'id' - the one produced by the USING clause, not either of the t2 or t3 ids.

My first impression is that this is a bug.  Especially since the query apparently executes in both left-join and right-join modes.

David J.

pgsql-general by date:

Previous
From: PALAYRET Jacques
Date:
Subject: Re: PostgreSQL query with FULL OUTER JOIN and subquery using column of GROUP BY expression ERROR: subquery uses ungrouped column from outer query
Next
From: PALAYRET Jacques
Date:
Subject: Re: PostgreSQL query with FULL OUTER JOIN and subquery using column of GROUP BY expression ERROR: subquery uses ungrouped column from outer query