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 E54AED1D432 for ; Wed, 4 Feb 2004 17:29:18 +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 71961-06 for ; Wed, 4 Feb 2004 13:29:09 -0400 (AST) Received: from davinci.ethosmedia.com (server228.ethosmedia.com [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 6132DD1D26A for ; Wed, 4 Feb 2004 13:29:09 -0400 (AST) Received: from [63.195.55.98] (HELO 192.168.1.29) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 4370514; Wed, 04 Feb 2004 09:30:05 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: =?iso-8859-1?q?J=FCrgen=20Cappel?= , "pgsql-sql" Subject: Re: Update from same table Date: Wed, 4 Feb 2004 09:28:08 -0800 User-Agent: KMail/1.5.4 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200402040928.08456.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/46 X-Sequence-Number: 16737 Jurgen, > UPDATE a.mytable from b.mytable > SET a.mycolumn = b.mycolumn > WHERE a.firstid = some_key > AND b.firstid = some_other_key > AND a.secondaryid = b.secondaryid; Very close, actually; you just need to fix the table alias: UPDATE mytable FROM mytable as b SET mytable.mycolumn = b.mycolumn WHERE mytable.firstid = some_key AND b.firstid = some_other_key AND mytable.secondaryid = b.secondaryid; AFAIK, one can't alias a table name in an UPDATE clause. So for that instance of the table, you need to use the full name. -- -Josh Berkus Aglio Database Solutions San Francisco