Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 7CE021337B53 for ; Wed, 26 Jan 2011 14:26:55 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 96454-09 for ; Wed, 26 Jan 2011 18:26:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from depesz.com (martin.depesz.com [188.40.39.14]) by mail.postgresql.org (Postfix) with ESMTP id F14051337B4E for ; Wed, 26 Jan 2011 14:26:47 -0400 (AST) Received: from martin.depesz.com ([188.40.39.14] helo=depesz.com) by depesz.com with esmtpa (Exim 4.69) (envelope-from ) id 1PiA4r-00058P-8e; Wed, 26 Jan 2011 19:26:45 +0100 Date: Wed, 26 Jan 2011 19:26:45 +0100 From: hubert depesz lubaczewski To: Joshua Farray Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #5850: UPDATE statement fails when using aliases Message-ID: <20110126182644.GA16967@depesz.com> Reply-To: depesz@depesz.com References: <201101261805.p0QI5eWP016518@wwwmaster.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <201101261805.p0QI5eWP016518@wwwmaster.postgresql.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201101/211 X-Sequence-Number: 29233 On Wed, Jan 26, 2011 at 06:05:40PM +0000, Joshua Farray wrote: > > The following bug has been logged online: > > Bug reference: 5850 > Logged by: Joshua Farray > Email address: farray@gmail.com > PostgreSQL version: 9.0.2 > Operating system: Win7 x64 > Description: UPDATE statement fails when using aliases > Details: > > Make a table: > > CREATE TABLE foos > > ( > > foo_id serial, > > foo_text varchar(255) > > ); > > Update the table using an alias: > > UPDATE foos AS t > > SET t.foo_text = ''; > > Expected output: > > UPDATE 0 > > Actual output: > > ERROR: column "t" of relation "foos" does not exist > > LINE 2: SET t.foo_text = ''; > > ^ you don't need to and can't use alias on the left side in assignment. proper query: update foos as t set foo_text = ''; this works even if you join another table that has foo_text column, as update knows which table you're updating. Best regards, depesz -- Linkedin: http://www.linkedin.com/in/depesz / blog: http://www.depesz.com/ jid/gtalk: depesz@depesz.com / aim:depeszhdl / skype:depesz_hdl / gg:6749007