pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: josh@agliodbs.com
Cc: sqllist <pgsql-sql@postgresql.org>
Subject: Re: No JOINs in UPDATE ... FROM?
Date: Thu, 26 Apr 2001 18:15:15 -0400
Message-ID: <25630.988323315@sss.pgh.pa.us> (raw)
In-Reply-To: <3AE85E1E.2D39D02D@agliodbs.com>
References: <3AE85E1E.2D39D02D@agliodbs.com>

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



view thread (2+ messages)

Message-ID: <25630.988323315@sss.pgh.pa.us>
Permalink:  ../25630.988323315@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/25630.988323315@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, josh@agliodbs.com
  Subject: Re: No JOINs in UPDATE ... FROM?
  In-Reply-To: <25630.988323315@sss.pgh.pa.us>
  References: <3AE85E1E.2D39D02D@agliodbs.com> <25630.988323315@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox