From: eric soroos <eric-psql@soroos.net>
To: pgsql-sql@postgresql.org
Subject: Re: Hairy question - transpose columns
Date: Wed, 23 Oct 2002 11:18:58 -0700
Message-ID: <47562919.1176750558@[4.42.179.151]> (raw)
In-Reply-To: <20021023105925.U7340-100000@megazone23.bigpanda.com>
> I'm sure there's a better way, but I think a series of union alls would
> do it but be rather computationally expensive.
>
> select cod_var, Year, Month, 1 as Day, RainDay1 as Rain
> where Ten=1
> union all
> select cod_var, Year, Month, 2 as Day, RainDay2 as Rain
> where Ten=1
You could do the following:
select cod_var, Year, Month, 1+((ten-1)*10) as Day, RainDay1 as Rain
where RainDay1 is not null
union all
select cod_var, Year, Month, 2+((ten-1)*10) as Day, RainDay2 as Rain
where RainDay2 is not null
..
I'm sure that there is a function that could do this too, but I'd tend to just convert the data and be done with it.
eric
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: eric-psql@soroos.net
Subject: Re: Hairy question - transpose columns
In-Reply-To: <47562919.1176750558@[4.42.179.151]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox