Re: Update Syntax - Mailing list pgsql-hackers

From Bruno Wolff III
Subject Re: Update Syntax
Date
Msg-id 20040202174904.GB4402@wolff.to
Whole thread Raw
In response to Update Syntax  (ramirez@idconcepts.org (Edwin S. Ramirez))
List pgsql-hackers
On Fri, Jan 30, 2004 at 07:41:18 -0800, "Edwin S. Ramirez" <ramirez@idconcepts.org> wrote:
> Hello,
> 
> I need Postgres support for the following update syntax :
> 
> update table1 set (col1, col2, col3) = (select f1, f2, f3 from table2
> where id=5) where rownum=3;
> 
> update table1 set (col1, col2, col3) = (select f1, f2, f3 from table2
> where id=table1.parentid) where rownum=3;
> 
> These type of update statements are the only ones supported by Oracle
> to update one table from another.

As a work around you could do:
update table1 set col1 = (select f1 from table2 where id=table1.parentid), col2 = (select f2 from table2 where
id=table1.parentid),col3 = (select f3 from table2 where id=table1.parentid) where rownum=3;
 

I don't think this will run as efficiently and it makes the query look
more complex, but it should work for both Oracle and Postgres.


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_restore bug in 7.4.1 ?
Next
From: Jan Wieck
Date:
Subject: Re: pg_stat_activity