getting jiggy with AS clauses - Mailing list pgsql-novice

From bille@npphotonics (Bill Eaton)
Subject getting jiggy with AS clauses
Date
Msg-id 001401c27ae5$bf7fd300$1a64a8c0@bille
Whole thread Raw
List 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@npphotonics.com

pgsql-novice by date:

Previous
From: Josh Berkus
Date:
Subject: Re: San Francisco Bay Area PostgreSQL User's Group
Next
From: Andrew McMillan
Date:
Subject: Re: [BUGS] Optimization disaster