Thread: quirk with update a from b

quirk with update a from b

From
"Mike G."
Date:
CREATE TABLE aa
(
a_col1 text
);

CREATE TABLE bb
(
b_col1 text
);

This update works:
UPDATE bb
SET b_col1 = aa.a_col1
FROM aa
WHERE bb.b_col1 <> aa.a_col1;

This does not:
UPDATE bb
SET bb.b_col1 = aa.a_col1
FROM aa
WHERE bb.b_col1 <> aa.a_col1;

Error: column "bb" of relation "bb" does not exist.

postgres 8.1.2

Maybe in a future version the alias can be allowed? Perhaps someone wanted to avoid updating the wrong column on
accidentand put this in as a safety net? 

Mike



Re: quirk with update a from b

From
Tom Lane
Date:
"Mike G." <mike@thegodshalls.com> writes:
> UPDATE bb
> SET bb.b_col1 = aa.a_col1
> FROM aa
> WHERE bb.b_col1 <> aa.a_col1;

> Error: column "bb" of relation "bb" does not exist.

> Maybe in a future version the alias can be allowed?

No.  It's contrary to SQL spec, and if we allowed it we'd have an
ambiguity: are you assigning to field b_col1 of bb, or assigning
to field b_col1 of a composite-type field named bb in table bb?

            regards, tom lane