From: | David Johnston <polobo(at)yahoo(dot)com> |
---|---|
To: | Robert James <srobertjames(at)gmail(dot)com> |
Cc: | Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Denormalizing via SQL |
Date: | 2011-12-12 00:44:23 |
Message-ID: | 1526E53F-3972-4042-AB19-F9C940D1E10D@yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Dec 11, 2011, at 19:40, Robert James <srobertjames(at)gmail(dot)com> wrote:
> I have a query returning:
>
> name | product_id
> Bob | 1
> Bob | 2
> Charles | 1
> Charles | 4
>
> To make it compatible with a legacy app, I need to convert it to this form:
> name | product_ids
> Bob | "1,2"
> Charles | "1,4"
>
> (Before you jump "That's not normal!" - I know. I didn't write the
> app. I just need to meet its interface.)
>
> What's the best way to do this in Postgres? Is there a way to do it
> via pure SQL?
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
Look at the STRING_AGG aggregate function.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Robert James | 2011-12-12 00:46:16 | Controlling complexity in queries |
Previous Message | Stefan Keller | 2011-12-12 00:42:32 | Howto to clear PostgreSQL cache and how to preload all tuples of a table into the cache? |