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
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
> -
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)
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