Re: Need sql to pull data from terribly architected table

From: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>
To: chris(at)chriscurvey(dot)com
Cc: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Need sql to pull data from terribly architected table
Date: 2012-10-23 19:21:38
Message-ID: CABvLTWFj_QqpOzEPqXPXY2cX5Py+S-0qszKLf0=S-EM0joJ=Fw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Oct 23, 2012 at 12:06 PM, Chris Curvey <chris(at)chriscurvey(dot)com>wrote:

> select my_ids.id
> , c1.value as col1
> , c2.value as col2
> , c3.value as col3
> , c4.value as col4
> , c5.value as col5
> from my_ids
> left join foo c1 on my_ids.id = c1.id
> left join foo c2 on my_ids.id = c2.id
> left join foo c3 on my_ids.id = c3.id
> left join foo c4 on my_ids.id = c4.id
> left join foo c5 on my_ids.id = c5.id
>

How about:

SELECT my_ids.id, ARRAY_AGG( ( property, valve ) order by property)
FROM my_ids
ORDER BY id;

--
Regards,
Richard Broersma Jr.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Broersma 2012-10-23 19:24:06 Re: Need sql to pull data from terribly architected table
Previous Message David Johnston 2012-10-23 19:08:40 Re: Need sql to pull data from terribly architected table