Correlated subquery/update

From: "Nick Fankhauser" <nickf(at)ontko(dot)com>
To: "pgsql-general" <pgsql-general(at)postgresql(dot)org>
Subject: Correlated subquery/update
Date: 2001-01-12 15:42:31
Message-ID: NEBBLAAHGLEEPCGOBHDGEEIHCHAA.nickf@ontko.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all-

I'm trying to match up two tables based on a primary key, and then copy
(update) a field in the second table to match a field in the first. Hard to
explain well... so here's an example:

select * from one;

a | b
---------
1 | null
2 | null

select * from two;

c | d
---------
1 | one
2 | two

In essence, I want to match up the records where one.a=two.c and update
one.b with the value in two.d . In Oracle, I would use this statement:

update one set b = (select d from two where one.a = two.c);

in psql, I get a syntax error when I do this. Either a correlated
subquery/update is not supported, or (more likely) I'm using the wrong
approach. Can anyone tell me whether this is supported, or how I can get the
job done using a different approach?

Thanks!
-Nick

---------------------------------------------------------------------
Nick Fankhauser

Business:
nickf(at)ontko(dot)com Phone 1.765.935.4283 Fax 1.765.962.9788
Ray Ontko & Co. Software Consulting Services http://www.ontko.com/

Personal:
nickf(at)fankhausers(dot)com http://www.fankhausers.com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-01-12 15:52:05 Re: Correlated subquery/update
Previous Message Tom Lane 2001-01-12 15:41:19 Re: union query