Re: GROUPing by expressions, and subSELECTs - Mailing list pgsql-sql

From Tom Lane
Subject Re: GROUPing by expressions, and subSELECTs
Date
Msg-id 14958.1014932420@sss.pgh.pa.us
Whole thread Raw
In response to GROUPing by expressions, and subSELECTs  (Shane Wright <me@shanewright.co.uk>)
Responses Re: GROUPing by expressions, and subSELECTs
List pgsql-sql
Shane Wright <me@shanewright.co.uk> writes:
> SELECT
>   [fields],
>   [expression],
>   (SELECT * FROM table2 WHERE [expression]) AS mynewfield
> FROM
>   table
> GROUP BY
>   [expression]

> But, it gives this error:

> ERROR: Sub-SELECT uses un-GROUPed attribute [table].[field] from outer 
> query

Yeah, the code is not bright enough to figure out that this could be
considered legitimate.  But try this:

SELECT [fields], myexpr, (SELECT * FROM table2 WHERE ss.myexpr) AS mynewfield
FROM (SELECT [fields],         [expression] as myexpr  FROM table  GROUP BY myexpr) AS ss
        regards, tom lane


pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Can't get rid of constraint
Next
From: "Andy Marden"
Date:
Subject: Re: Left Outer Join Question