Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Re: What is wrong with this PostgreSQL UPDATE statement??


  • From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
  • To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
  • Cc: Steve Johnson <stevej456(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
  • Subject: Re: What is wrong with this PostgreSQL UPDATE statement??
  • Date: Fri, 22 Aug 2008 22:50:10 -0400
  • Message-id: <23096.1219459810@sss.pgh.pa.us> <text/plain>

Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)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



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group