Re: Column as arrays.. more efficient than columns?

From: Ow Mun Heng <Ow(dot)Mun(dot)Heng(at)wdc(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Column as arrays.. more efficient than columns?
Date: 2007-09-07 00:37:29
Message-ID: 1189125449.17218.7.camel@neuromancer.home.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Nobody has any comments on this??

On Thu, 2007-09-06 at 12:22 +0800, Ow Mun Heng wrote:
> Table is like
>
> create table foo (
> number int,
> subset int,
> value int
> )
>
> select * from foo;
> number | subset | value
> 1 1 1
> 1 2 2
> 1 3 10
> 1 4 3
>
> current query is like
>
> select number,
> avg(case when subset = 1 then value else null end) as v1,
> avg(case when subset = 2 then value else null end) as v2,
> avg(case when subset = 3 then value else null end) as v3,
> avg(case when subset = 4 then value else null end) as v4
> from foo
> group by number
>
> results
> ------
> number | v1 | v2 | v3 | v4
> 1 1 2 10 4
>
>
> I'm thinking of denormalising it a bit and put it either as an array or
> just create a new table with the end result like the above.
>
> I just want to know which is more efficient. Users can just do a
>
> select * from new_foo where number = 'X';
>
>
> Thanks.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Glaesemann 2007-09-07 00:52:22 Re: Column as arrays.. more efficient than columns?
Previous Message brian 2007-09-07 00:35:16 Re: log_statement and PREPARE