X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 72BB3475925 for ; Mon, 10 Feb 2003 16:39:01 -0500 (EST) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id BE8EE47590C for ; Mon, 10 Feb 2003 16:39:00 -0500 (EST) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 2832994; Mon, 10 Feb 2003 13:39:08 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: greg@turnstep.com, pgsql-sql@postgresql.org Subject: Re: conversi ms-sql7 vs postgresql 7.3 Date: Mon, 10 Feb 2003 13:40:54 -0800 X-Mailer: KMail [version 1.4] References: <8632f12da1f37b38ed7a9264c07c5bdb@biglumber.com> In-Reply-To: <8632f12da1f37b38ed7a9264c07c5bdb@biglumber.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200302101340.54373.josh@agliodbs.com> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/208 X-Sequence-Number: 11606 Greg, > > command in ms-sql 7 can use calculate field (column) balance from id=3D1 > > to id=3D4: "update xx set bal=3Dbalance=3Dbal+debet-credit" >=20 > You cannot do such a thing in SQL alone: you must use a procedural=20 > language. One way is with plpgsql: You're mistaken, I think (I can't find the original e-mail in this thread) UPDATE totals SET balance =3D total_bal FROM (SELECT acct_id, (sum(credit) - sum(debit)) as total_bal FROM accounts GROUP BY acct_id) tb WHERE tb.acct_id =3D totals.acct_id AND totals.acct_id =3D $selection ... would update a ficticious "totals" table with the sum of credits and=20 debits for a particular account. --=20 -Josh Berkus Aglio Database Solutions San Francisco