From: pgsql-general-owner@postgresql.org [mailto:pgsql-general-owner@postgresql.org] On Behalf Of Richard Broersma Sent: Tuesday, October 23, 2012 3:24 PM To: chris@chriscurvey.com Cc: Gauthier, Dave; pgsql-general@postgresql.org Subject: Re: [GENERAL] Need sql to pull data from terribly architected table
SELECT my_ids.id, ARRAY_AGG( ( property, value ) order by (property, value) ) FROM my_ids
GROUP BY id
ORDER BY id;
-- Regards, Richard Broersma Jr.
-- Regards, Richard Broersma Jr.
The main problem with this code is that the length of the array varies between rows depending on which attributes are missing entries. You would want to generate dummy records for any missing attributes and then apply the ARRAY_AGG.