pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #5850: UPDATE statement fails when using aliases
2+ messages / 2 participants
[nested] [flat]

* BUG #5850: UPDATE statement fails when using aliases
@ 2011-01-26 18:05  Joshua Farray <farray@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Joshua Farray @ 2011-01-26 18:05 UTC (permalink / raw)
  To: pgsql-bugs


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 = '';
>             ^



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #5850: UPDATE statement fails when using aliases
@ 2011-01-26 18:26  hubert depesz lubaczewski <depesz@depesz.com>
  parent: Joshua Farray <farray@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: hubert depesz lubaczewski @ 2011-01-26 18:26 UTC (permalink / raw)
  To: Joshua Farray <farray@gmail.com>; +Cc: pgsql-bugs

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2011-01-26 18:26 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-01-26 18:05 BUG #5850: UPDATE statement fails when using aliases Joshua Farray <farray@gmail.com>
2011-01-26 18:26 ` hubert depesz lubaczewski <depesz@depesz.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox