do I need a table function to do this? - Mailing list pgsql-general

From Kirk Wythers
Subject do I need a table function to do this?
Date
Msg-id 4C361B10-EC3E-4F58-A26B-407CAF8927A2@umn.edu
Whole thread Raw
Responses Re: do I need a table function to do this?  (Serge Fonville <serge.fonville@gmail.com>)
List pgsql-general
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
combinethese one variable at a time. Something like this (I'm not using the word join, because I don't think this is a
joinin 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?






pgsql-general by date:

Previous
From: Wolfgang Keller
Date:
Subject: Re: Tool to create database diagrams in postgreSQL
Next
From: Kirk Wythers
Date:
Subject: do I need a table function to do this