Re: how to build this string ?

From: "Richard Huxton" <dev(at)archonet(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>, <juerg(dot)rietmann(at)pup(dot)ch>
Subject: Re: how to build this string ?
Date: 2001-03-22 14:42:12
Message-ID: 002501c0b2de$48e19100$1001a8c0@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

From: <juerg(dot)rietmann(at)pup(dot)ch>

> Hello there

Hello again Juerg - I take it you got that monster query working after?

> Is it possible (and I think it is) to do the following :
>
> I have a table with diameters and types. I need to build a comma separated
> string.
>
> typ diam
> 01 800
> 01 840
> 01 870
> 01 1120
>
> select diam from zylinder where typ='01'
>
> should produce the string "800,840,870,1120"

You'll want to build yourself a custom aggregate function. Check the mail
archives for someone else who did this recently (in the last month or so,
Tom Lane was involved in the discussion too). I forget the fella's name, but
he should have almost exactly what you want.

You can then do something like:

select typ, commify(diam) from zylinder group by typ;

- Richard Huxton

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Antti Linno 2001-03-22 14:50:33 Birthday search.
Previous Message Johannes Grødem 2001-03-22 14:18:47 Foreign key referencing subclasses.