Saving result set of SELECT to table column

From: Patric <lists(at)p-dw(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Saving result set of SELECT to table column
Date: 2008-01-14 18:19:36
Message-ID: 478BA7B8.2090907@p-dw.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hi,
There will be some flames i suppose.
Well I've a normalized database..
For instance:

create table Y ( pk, data... );
create table Z ( pk , data... );

create table X ( char, references Y, references Z);

SELECT * from X;

Now I want to make a listing of the result set from X.
If there are references to Z or Y (not null refs), I want to display
that data too.

Normally I would SELECT, to get that data, not in my case.
Nearly all queries will be SELECTs, no UPDATEs or INSERTs, so need to
optimize that case.

The dirty little denormalization would look like this:

create table X ( char, ref. to Y, ref. to Z, StoreY Y , StoreZ Z);

On insert or update of Z or Y, I would update these two (StoreY,
StoreZ) columns by RULE or TRIGGER..
I know this is not nice etc.. Codd would sue for this, but in my case
performance over beauty is ok.
I'm looking for something like UPDATE X set StoreY=(SELECT * FROM Y
WHERE pk=4) WHERE foreignID2Y = 4;

Is there a away to accomplish this straightforward in a single
statement without doing loops and stuff in a serverside procedure?

Thanks in advance,
Patric


Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Ansgar -59cobalt- Wiechers 2008-01-14 18:38:38 Re: Saving result set of SELECT to table column
Previous Message Tom Lane 2008-01-14 15:22:14 Re: Linux/PostgreSQL scalability issue - problem with 8 cores