Re: [GENERAL] combine multiple row values in to one row

2009-07-07 Thread David Fetter
On Tue, Jul 07, 2009 at 08:40:06AM -0700, David Fetter wrote: > On Tue, Jul 07, 2009 at 01:59:35AM +0430, Lee Harr wrote: > > > > Is there a generic way to do this? An aggregate maybe? > > The aggregate is called array_agg() and it's in 8.4. You can then > wrap array_to_string() around it and ge

Re: [GENERAL] combine multiple row values in to one row

2009-07-07 Thread David Fetter
On Tue, Jul 07, 2009 at 01:59:35AM +0430, Lee Harr wrote: > > Hi; > > I'm looking for a way to do this: > > > # \d tbl > Table "public.tbl" > Column | Type | Modifiers > +-+--- > idn| integer | > code | text| > # SELECT * FROM tbl; > idn | code > -

Re: [GENERAL] combine multiple row values in to one row

2009-07-07 Thread Hartman, Matthew
Try this. select idn, array_to_string(array(select code from tbl t2 where t2.idn = t1.idn order by code), ', ') as codes fromtbl t1 group byidn order byidn Matthew Hartman Programmer/Analyst Information Management, ICP Kingston General Hospital (613)

Re: [GENERAL] combine multiple row values in to one row

2009-07-06 Thread Ivan Sergio Borgonovo
On Tue, 7 Jul 2009 01:59:35 +0430 Lee Harr wrote: > > Hi; > > I'm looking for a way to do this: > # select idn, magic() as codes FROM tbl; > idn | codes > -+-- >1 | A >2 | B, C >3 | A, C, E > (3 rows) > > > Right now, I use plpgsql functions, but each time I do it > I ha