pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
how to build this string ?
2+ messages / 2 participants
[nested] [flat]

* how to build this string ?
@ 2001-03-22 14:05 juerg.rietmann@pup.ch
  2001-03-22 14:42 ` Re: how to build this string ? Richard Huxton <dev@archonet.com>
  0 siblings, 1 reply; 2+ messages in thread

From: juerg.rietmann@pup.ch @ 2001-03-22 14:05 UTC (permalink / raw)
  To: pgsql-sql

Hello there

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
02        760
02        780
02        800
02        900
03        1200
03        1234
03        1352

select diam from zylinder where typ='01'

should produce the string "800,840,870,1120"

Thanks for any help ... jr

============================================
PFISTER + PARTNER, SYSTEM - ENGINEERING AG
Juerg Rietmann
Grundstrasse 22a
6343 Rotkreuz
Switzerland

phone: +4141 790 4040
fax: +4141 790 2545
mobile: +4179 211 0315
============================================




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: how to build this string ?
  2001-03-22 14:05 how to build this string ? juerg.rietmann@pup.ch
@ 2001-03-22 14:42 ` Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Huxton @ 2001-03-22 14:42 UTC (permalink / raw)
  To: pgsql-sql; juerg.rietmann@pup.ch

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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-03-22 14:42 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-22 14:05 how to build this string ? juerg.rietmann@pup.ch
2001-03-22 14:42 ` Richard Huxton <dev@archonet.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox