Re: Advanced SELECT - Mailing list pgsql-sql

From Richard Huxton
Subject Re: Advanced SELECT
Date
Msg-id 421D8EA6.7020107@archonet.com
Whole thread Raw
In response to Advanced SELECT  (Kai Hessing <kai.hessing@hobsons.de>)
Responses Re: Advanced SELECT  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Advanced SELECT  (Kai Hessing <kai.hessing@hobsons.de>)
List pgsql-sql
Kai Hessing wrote:
> 
> The normal clause would look like:
> 
> SELECT c.companyname, s.sectorname FROM company c, sector s,
> company_sector cs WHERE cs.cid = c.cid AND cs.sid = s.sid ORDER BY
> c.companyname;

> c.companyname  | ??? (sectors)
> ---------------+------------------------
> company1          | sectora, sectorb
> company2          | sectora, sectorb, sectorc
> company3          | sectora
> company4          | sectorc
> 

Search the mailing-list archives for "custom aggregate concat" and 
you'll quickly find an example of how to write your own custom aggregate 
(like SUM()).

Warning - I don't think you can guarantee the order of elements in the 
aggregated sectors.

--  Richard Huxton  Archonet Ltd


pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Software for database-visualisation
Next
From: Richard Huxton
Date:
Subject: Re: Junk queries with variables?