I Have a large number of queries some of which can take half an hour to run, many of these queries return over 20 or so columns( yes they are normalised). I am interested in storing all of this data in a single table, in the format for Timestamp, name, value, the reson for this is for later automation on the data.
However when I have a query that returns
T1, V1t1, V2t1, V3t1
T2, V1t2, v2t2, v3t2
-- -- -- --
and I wish to have the data in format
T1, Name(V1), V1t1
T1, Name(V2), V2t1
T1, Name(V3), V3t1
T2, Name(V1), V1t2
T2, Name(V2), V2t2
T2, Name(V3), V3t2
I know I Could do this by doing a union on selects for each value v1, v2 and v3,
however I am interested in speed and would like to refrain from issuing 3 queries where I can get the data(albeit in the wroung format) in one.. or in the real case refrain from issuing 20-30 queries where it can be done in one.
so the question is , is there a way to do this apart from dumping into a temporary table and running subsequent selects onto the relevant columns of the table and unioning them together..
would this be possible with a custom built postgresql function?
thanks in advance