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

From Stephan Szabo
Subject Re: What is wrong with this PostgreSQL UPDATE statement??
Date
Msg-id 20080822183519.O68023@megazone.bigpanda.com
Whole thread Raw
In response to What is wrong with this PostgreSQL UPDATE statement??  ("Steve Johnson" <stevej456@gmail.com>)
Responses Re: What is wrong with this PostgreSQL UPDATE statement??
List pgsql-sql
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);

At least as of SQL2003, I think both of the above use extensions, so
there's no guarantee to the behavior on different systems and to do it
with a standard query, you'd need to use a subselect, something like:

update certgroups c set termgroupname = (select termgroupname from
termgroup tg where (c.days >= tg.mindays) and (c.days <=tg.maxdays));



pgsql-sql by date:

Previous
From: "Steve Johnson"
Date:
Subject: What is wrong with this PostgreSQL UPDATE statement??
Next
From: Tom Lane
Date:
Subject: Re: What is wrong with this PostgreSQL UPDATE statement??