X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4027014B2806 for ; Mon, 9 Aug 2004 17:16:42 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48850-05 for ; Mon, 9 Aug 2004 20:16:33 +0000 (GMT) Received: from mail.dialmex.net (67.107.77.98.ptr.us.xo.net [67.107.77.98]) by svr1.postgresql.org (Postfix) with ESMTP id D5E7414B280B for ; Mon, 9 Aug 2004 17:16:29 -0300 (ADT) Received: from david.dialmex.net (dmxnocws13.dialmex.net [67.107.77.78]) by mail.dialmex.net (Postfix) with ESMTP id CEE42EE993 for ; Mon, 9 Aug 2004 15:16:30 -0500 (CDT) Received: by david.dialmex.net (Postfix, from userid 4001) id 193D314AD689; Mon, 9 Aug 2004 15:16:30 -0500 (CDT) Subject: UPDATE FROM problem, multiple updates of same row don't seem to work From: David Stanaway To: pgsql-sql Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Mon, 09 Aug 2004 15:16:29 -0500 Message-Id: <1092082589.7197.3.camel@dmxnocws13.dialmex.net> Mime-Version: 1.0 X-Mailer: Evolution 1.5.9.1 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200408/69 X-Sequence-Number: 18566 Here is an example: CREATE TABLE tablea( id int PRIMARY KEY, flag int ); CREATE TABLE tableb( aid int REFERENCES tablea(id), flag int ); INSERT INTO tablea VALUES(1,0); INSERT INTO tablea VALUES(2,0); -- Flags for 1st row of tablea - When ORed, should be 7 INSERT INTO tableb VALUES(1,1); INSERT INTO tableb VALUES(1,2); INSERT INTO tableb VALUES(1,4); -- Flags for 2nd row of tablea - When ORed, should be 5 INSERT INTO tableb VALUES(2,1); INSERT INTO tableb VALUES(2,4); UPDATE tablea SET flag = tablea.flag | tableb.flag FROM tableb WHERE tablea.id = tableb.aid; SELECT * from tablea; id | flag ----+------ 1 | 1 2 | 1 -- Desired output is id | flag ----+------ 1 | 7 2 | 5 Is there a way around this so that I can get the desired output? -- David Stanaway