Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic view or temp table in Postgres?

Status
Not open for further replies.

oppcos

Programmer
Dec 1, 2004
209
US
Hi,
I'm suffering from some db ignorance. I was trying to do the following in another database and found that I couldn't and wanted to know if Postgres is able. Essentially I'm trying to rotate a table for the purpose of my view. Here's an example.

First, I have a table like this:
Code:
 _________   ________   _____   _____
[prime_key] [Field_ID] [Field] [Class]
 ---------   --------   -----   -----
         1         1A   'foo'     'A'
         2         2A   'bar'     'A'
         3         1A   'tst'     'B'
         4         3A   'hi.'     'B'

I am trying to create a sql statement that returns this data rearranged into a view or temp table that utilizes the Class for its headers so it looks like this:
Code:
 ________       _       _   
[Field_ID]     [A]     [B]
 --------   -----   -----
       1A   'foo'   'tst'
       2A   'bar'    null
       3A    null   'hi.'

There could be many different 'Class'es and I want the columns returned to be dynamic according to however many Classes are set and using the Field_ID for the primary key of the newly created view/table. Hope that makes sense. Is Postgres the way to go?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top