Re: do I need a table function to do this?

From: Serge Fonville <serge(dot)fonville(at)gmail(dot)com>
To: Kirk Wythers <kwythers(at)umn(dot)edu>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: do I need a table function to do this?
Date: 2012-12-29 22:06:18
Message-ID: CAOAS_+KbXPcUvCpdEu9AjL_tKvoYAFzjmKYcLMpoQA=PquCKyg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Assuming the columns in t2 are fixed, you should be able fairly easy solve
this using a cursor.

HTH
Kind regards/met vriendelijke groet,

Serge Fonville

http://www.sergefonville.nl

Convince Microsoft!
They need to add TRUNCATE PARTITION in SQL Server
https://connect.microsoft.com/SQLServer/feedback/details/417926/truncate-partition-of-partitioned-table

2012/12/29 Kirk Wythers <kwythers(at)umn(dot)edu>

> I have been given an interesting problem to solve in a postgres db. I was
> given two tables
>
> t1:
>
>
> site treatment variable id (pk)
> -------------------------------------------------------------
> A X BLUE 1A
> B Y RED 2B
> A Y GREEN 3A
>
>
>
> t2:
>
> rowid (pk) timestamp BLUE RED
> GREEN
>
> -----------------------------------------------------------------------------------------
> 1 1332493200 3.4
> 2.1 5.8
> 2 1332496800 3.2
> 2.0 5.8
> 3 1332500400 3.3
> 2.2 6.0
>
>
> I need to combine the site and treatment information from t1 with the
> variable records in t2. I think I will have to combine these one variable
> at a time. Something like this (I'm not using the word join, because I
> don't think this is a join in the regular sense. It's more like some kind
> of crazy pivot table thing!):
>
> t3:
>
> rowid (pk) timestamp BLUE site
> treatment
>
> -------------------------------------------------------------------------------------
> 1 1332493200 3.4 A
> X
> 2 1332496800 3.2 A
> X
> 3 1332500400 3.3 A
> X
>
> and then:
>
> t4
>
> rowid (pk) timestamp RED site
> treatment
>
> -------------------------------------------------------------------------------------
> 1 1332493200 2.1 B
> Y
> 2 1332496800 2.0 B
> Y
> 3 1332500400 2.2 B
> Y
>
>
> Is this even possible?
>
>
>
>
>
>
> --
> 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
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bryan Lee Nuse 2012-12-29 22:18:27 Re: do I need a table function to do this
Previous Message Kirk Wythers 2012-12-29 21:45:45 do I need a table function to do this