getting jiggy with AS clauses

From: "bille(at)npphotonics (Bill Eaton)" <bille(at)npphotonics(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: getting jiggy with AS clauses
Date: 2002-10-23 22:44:28
Message-ID: 001401c27ae5$bf7fd300$1a64a8c0@bille
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

It would be really nice to be able to get column labels from
within the database. Or in other words, trick the AS clause
into returning info from a SELECT query, i.e.
SELECT header AS (SELECT header from labheaders where
dataset=1) FROM ...

Let's say you've got several columns of data from the
laboratory. It would be nice if I could store the column
headers in one place (LabHeaders) and store the data in
another place (LabData)

LabHeaders LabData
---------- --------
dataset int8 <--> dataset int8
headers text[] row int8
labrawdata float8[]

The tricky part is constructing a query that returns
something like

row MyColumnDataFromLabHeadersTable
---- ---------------------------------
1 3.1415927
2 2.7128
3 5.3

Why not just used static column names, you ask? Well, we can
pretty much rest assured that the things that are measured
will occasionally change. And it's pretty silly to add a new
table every time a change is made.

I've played a bit with writing functions that return SETOF,
but with little success.

Ideas?

Bill Eaton
mailto://bill(at)npphotonics(dot)com

Browse pgsql-novice by date

  From Date Subject
Next Message Andrew McMillan 2002-10-24 00:02:15 Re: [BUGS] Optimization disaster
Previous Message Radhesh Mohandas 2002-10-23 21:15:36 Re: [ANNOUNCE] San Francisco Bay Area PostgreSQL User's Group