Re: What is wrong with this PostgreSQL UPDATE statement?? - Mailing list pgsql-sql

From Tom Lane
Subject Re: What is wrong with this PostgreSQL UPDATE statement??
Date
Msg-id 23096.1219459810@sss.pgh.pa.us
Whole thread Raw
In response to Re: What is wrong with this PostgreSQL UPDATE statement??  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
List pgsql-sql
Stephan Szabo <sszabo@megazone.bigpanda.com> writes:
> On Fri, 22 Aug 2008, Steve Johnson wrote:
>> update certgroups
>> set termgroupname = tg.termgroupname
>> from certgroups c, termgroup tg
>> where (c.days >= tg.mindays) and (c.days <= tg.maxdays);

> In recent PostgreSQL versions I believe this is properly written:
> update certgroups c
> set termgroupname = tg.termgroupname
> from termgroup tg
> where (c.days >= tg.mindays) and (c.days <= tg.maxdays);

Yeah, in PG's eyes the former is creating a cartesian join between two
versions of certgroups.  I think MSSQL interprets the FROM reference as
being the same as the update target, but we don't.

> At least as of SQL2003, I think both of the above use extensions,

Correct, the standard disallows a FROM clause altogether; and I'm not
sure that they weren't right.  No matter which way you resolve the above
ambiguity, you've still got the problem that the update behavior is
ill-defined if a given target row joins to more than one set of rows
from the other table(s).
        regards, tom lane


pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: What is wrong with this PostgreSQL UPDATE statement??
Next
From: "Scott Marlowe"
Date:
Subject: Re: [ADMIN] Regarding access to a user