X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.225.181]) by svr1.postgresql.org (Postfix) with ESMTP id AF644CC3D3 for ; Tue, 15 Jul 2003 15:14:38 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr5.postgresql.org [64.117.225.181]) (amavisd-new, port 10024) with ESMTP id 40333-02 for ; Tue, 15 Jul 2003 15:14:57 +0000 (GMT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 6C9CFCC3C6 for ; Tue, 15 Jul 2003 12:14:27 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h6FFEuQ3022672; Tue, 15 Jul 2003 11:14:56 -0400 (EDT) To: Erik Thiele Cc: pgsql-sql@postgresql.org Subject: Re: summing tables In-reply-to: <20030715143925.54716ed4.erik@thiele-hydraulik.de> References: <20030715140921.7c5a6a6c.erik@thiele-hydraulik.de> <001501c34aca$e70ca280$0600a8c0@fix.ro> <20030715143925.54716ed4.erik@thiele-hydraulik.de> Comments: In-reply-to Erik Thiele message dated "Tue, 15 Jul 2003 14:39:25 +0200" Date: Tue, 15 Jul 2003 11:14:56 -0400 Message-ID: <22671.1058282096@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/179 X-Sequence-Number: 14293 Erik Thiele writes: > "Viorel Dragomir" wrote: >> update table_name >> set c = a + b + (select c from table_name as x where x.seq = seq-1) >> where c is null; > hmmm. the query is run row by row, isn't it? > but it will have different results depending on the order of those rows. No, it won't, because the SELECTs will not see the changes from the not-yet-completed UPDATE. The above command is almost right; it needs to be update table_name set c = a + b + (select c from table_name as x where seq = table_name.seq-1) where c is null; because inside the sub-SELECT, unadorned "seq" will refer to the SELECT's table. You didn't say exactly what you wanted to do with null inputs, so that issue may need more thought. regards, tom lane