Re: No JOINs in UPDATE ... FROM?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: No JOINs in UPDATE ... FROM?
Дата
Msg-id 25630.988323315@sss.pgh.pa.us
обсуждение исходный текст
Ответ на No JOINs in UPDATE ... FROM?  (Josh Berkus <josh@agliodbs.com>)
Список 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 по дате отправления:

Предыдущее
От: Jan Wieck
Дата:
Сообщение: Re: rules
Следующее
От: Vivek Khera
Дата:
Сообщение: Re: MySql 'REPLACE'