Re: No JOINs in UPDATE ... FROM? - Mailing list pgsql-sql

From Tom Lane
Subject Re: No JOINs in UPDATE ... FROM?
Date
Msg-id 25630.988323315@sss.pgh.pa.us
Whole thread Raw
In response to No JOINs in UPDATE ... FROM?  (Josh Berkus <josh@agliodbs.com>)
List pgsql-sql
Josh Berkus <josh@agliodbs.com> writes:
> UPDATE assignments SET status = -1
> FROM assignments JOIN orders ON assignments.order_usq = orders.usq
> WHERE orders.status = -1;

>     However, I get an error of "Relation assignments referenced twice in
> query."  

>     Now, I can (and have) re-phrase the query so that PostgreSQL will
> accept it.  However, I was under the impression that the above was
> standard SQL92.  Am I mistaken?

You are mistaken.  SQL92 and SQL99 don't allow a FROM clause in UPDATE
at all: they say it's just
        <update statement: searched> ::=             UPDATE <target table>               SET <set clause list>
    [ WHERE <search condition> ]
 

Postgres allows the clause, but treats it as supplying *additional*
table references besides the target table reference.  Thus the error.

In other words: you can JOIN, but not against the target table.
        regards, tom lane


pgsql-sql by date:

Previous
From: Jan Wieck
Date:
Subject: Re: rules
Next
From: Vivek Khera
Date:
Subject: Re: MySql 'REPLACE'