Re: how to build this string ? - Mailing list pgsql-sql

From Richard Huxton
Subject Re: how to build this string ?
Date
Msg-id 002501c0b2de$48e19100$1001a8c0@archonet.com
Whole thread Raw
In response to how to build this string ?  (juerg.rietmann@pup.ch)
List pgsql-sql
From: <juerg.rietmann@pup.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



pgsql-sql by date:

Previous
From: Antti Linno
Date:
Subject: Birthday search.
Next
From: Tom Lane
Date:
Subject: Re: CHAR or VARCHAR