Re: [BUGS] Update using sub-select table in schema - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [BUGS] Update using sub-select table in schema
Date
Msg-id 11183.1159803525@sss.pgh.pa.us
Whole thread Raw
Responses Re: [BUGS] Update using sub-select table in schema  (Simon Riggs <simon@2ndquadrant.com>)
List pgsql-hackers
Chris Dunlop <chris@onthe.net.au> writes:
> I'm not sure if this is a bug or if it's displaying my ignorance
> of this corner of SQL...

> update a set name = (
>   select name
>   from temp.a
>   where temp.a.id = a.id
> )

Postgres treats "FROM temp.a" the same as "FROM temp.a AS a", and then
the "a.id" references that rather than the outer query's A.  Try just
"select name from temp.a where temp.a.id = a.id;" to see this in action.

Looking at the SQL spec, I'm having a hard time finding any verbiage
that either confirms or denies this interpretation.  It says that a FROM
item without a correlation name (ie, an AS alias) exposes the table
name, and then a column reference can refer to the table name, but it's
not at all clear whether the table name must be qualified or not in the
reference.  Comments anyone?
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Another idea for dealing with cmin/cmax
Next
From: "Strong, David"
Date:
Subject: Re: Faster StrNCpy