Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 6448D2E30BD for ; Mon, 14 Jan 2008 14:19:40 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 39304-10 for ; Mon, 14 Jan 2008 14:19:37 -0400 (AST) Received: from smtpout2.pt.lu (smtpout2.pt.lu [194.154.192.94]) by postgresql.org (Postfix) with ESMTP id 607A12E30A4 for ; Mon, 14 Jan 2008 14:19:37 -0400 (AST) Received: from [192.168.2.2] (ip-88-207-144-112.dyn.luxdsl.pt.lu [88.207.144.112] (may be forged)) by smtpout2.pt.lu with ESMTP id m0EIJZLG017502 for ; Mon, 14 Jan 2008 19:19:35 +0100 Message-ID: <478BA7B8.2090907@p-dw.com> Date: Mon, 14 Jan 2008 19:19:36 +0100 From: Patric User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Saving result set of SELECT to table column Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/119 X-Sequence-Number: 28358 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