X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 5BD11D1B538 for ; Wed, 29 Oct 2003 17:43:48 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 67349-03 for ; Wed, 29 Oct 2003 13:43:17 -0400 (AST) Received: from davinci.ethosmedia.com (unknown [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 76A80D1B89A for ; Wed, 29 Oct 2003 13:43:16 -0400 (AST) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3839994; Wed, 29 Oct 2003 09:43:57 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Jeff Kowalczyk , pgsql-sql@postgresql.org Subject: Re: Help on update that subselects other records in table, uses joins Date: Wed, 29 Oct 2003 09:42:57 -0800 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200310290942.57584.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/386 X-Sequence-Number: 15786 Jeff, > UPDATE ordercharges INNER JOIN orders ON > orders.orderid = ordercharges.orderid > SET orderchargeasbilled = You may only UPDATE one table at a time, you can't update a JOIN. So when selecting from another table to filter or calculate your update, the form is: UPDATE orderchanges SET orderchargesbilled = {expression} FROM orders WHERE orders.orderid = ordercharges.orderid AND etc. Second, your value expression for the update is a subselect which includes a select on the table and field you are updating! This is a recursive loop and a very bad idea; gods only know what you'll end up with. I suggest Joe Conway's "SQL for Smarties" or "SQL Queries for Mere Mortals" from another author. -- Josh Berkus Aglio Database Solutions San Francisco