Re: Sorting items in aggregate function - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: Sorting items in aggregate function
Date
Msg-id 20060912181759.GA66966@winnie.fuhr.org
Whole thread Raw
In response to Sorting items in aggregate function  (Steven Murdoch <psql+Steven.Murdoch@cl.cam.ac.uk>)
Responses Re: Sorting items in aggregate function
List pgsql-sql
On Tue, Sep 12, 2006 at 04:46:28PM +0100, Steven Murdoch wrote:
> Here is an example of a setup and what I could like to achieve. Does
> anyone have suggestions on what is the best way to get the desired
> result?

Use the aggregate over an ordered subquery:

SELECT name, trim(concat(code || ' ')) AS codes
FROM ( SELECT a.name, b.code FROM a LEFT JOIN ab ON a.id = ab.a_id LEFT JOIN b ON ab.b_id = b.id ORDER BY b.code
) AS s
GROUP BY name
ORDER BY name;

Here's a comment from Tom Lane, one of the core developers, on
feeding the aggregate based on the subquery's order:

http://archives.postgresql.org/pgsql-general/2005-09/msg00047.php

-- 
Michael Fuhr


pgsql-sql by date:

Previous
From: Daryl Richter
Date:
Subject: Re: Joint a table back on itself?
Next
From: "Aaron Bono"
Date:
Subject: Re: on connect/on disconnect