Re: UPDATE .. FROM - Mailing list pgsql-sql

From Tom Lane
Subject Re: UPDATE .. FROM
Date
Msg-id 12016.1204897661@sss.pgh.pa.us
Whole thread Raw
In response to UPDATE .. FROM  ("Markus Bertheau" <mbertheau.pg@googlemail.com>)
List pgsql-sql
"Markus Bertheau" <mbertheau.pg@googlemail.com> writes:
> I'm kind of stuck as to why postgresql doesn't understand what I mean in the
> following queries:

> UPDATE tag_data td SET td.usage_counter = td.usage_counter + 1 FROM
> tag_list_tag_data ltd WHERE ltd.tag_id = td.id AND ltd.id =  102483;
> ERROR:  column "td" of relation "tag_data" does not exist

You aren't supposed to specify a table name (nor alias) for a target
variable in a SET clause.  It's useless (since you can't update more
than one table) and it's ambiguous because of the possibility of
composite fields.  What you want is something like

UPDATE tag_data td SET usage_counter = td.usage_counter + 1 FROM ...
        regards, tom lane


pgsql-sql by date:

Previous
From: "Yura Gal"
Date:
Subject: Re: RETURN QUERY generates error
Next
From: "Jamie Tufnell"
Date:
Subject: Re: Composite UNIQUE across two tables?