Skip site navigation (1) Skip section navigation (2)

GROUP BY Wildcard Syntax Thought

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: GROUP BY Wildcard Syntax Thought
Date: 2011-05-04 19:28:24
Message-ID: 00ab01cc0a91$6fd24a50$4f76def0$@yahoo.com (view raw or flat)
Thread:
Lists: pgsql-general
When specifying columns in a GROUP BY clause would it be possible to use a
wildcard to specify all columns coming from a given relation?

 

SELECT 

rosum.*, 

sum(ld.amount) AS ldcost, 

count(ld.amount) AS ldcount, 

rosum.rocost + sum(ld.amount) AS netbal

 

FROM (

SELECT w.s_id, w.accountnumber, w.date_reference, w.invoicenumber, 

sum(w.amount_cost) AS rocost, count(w.amount_cost) AS rocount

FROM wiplaboradpstaging w

WHERE <FILTER>

GROUP BY w.s_id, w.accountnumber, w.date_reference, w.invoicenumber

) rosum

 

LEFT JOIN ledgerdetail ld ON (

rosum.s_id = ld.s_id AND 

rosum.accountnumber = ld.accountnumber AND 

rosum.invoicenumber = ld.reference

)

 

GROUP BY rosum.*  < ------- WildCard Group By Since the rosum sub-query has
already been subjected to a GROUP BY

 

Attempt to run this query in 9.0.3 results in:

 

"SQL Error: ERROR:  column "rosum.s_id" must appear in the GROUP BY clause
or be used in an aggregate function

LINE 2: rosum.*,"

 

David J.

 

 

 

 

Responses

pgsql-general by date

Next:From: Misa SimicDate: 2011-05-04 19:39:02
Subject: Re: pervasiveness of surrogate (also called synthetic) keys
Previous:From: David BorehamDate: 2011-05-04 19:24:17
Subject: Fwd: Re: SSDD reliability

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group