Re: Using a CTE for an update

From: Bosco Rama <postgres(at)boscorama(dot)com>
To: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Cc: David Salisbury <salisbury(at)globe(dot)gov>
Subject: Re: Using a CTE for an update
Date: 2013-05-31 22:45:37
Message-ID: 51A92811.9080802@boscorama.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 05/31/13 15:33, David Salisbury wrote:
>
> And without trying too much ;), I'll bet there is no way to do this in SQL proper. i.e.
> I can't correlate an update with a select stmt, as in a correlated sub-query sort of way.
> So for this to work I would indeed need to write a function that "hard codes" the values
> within the update stmt.

I think this is what you want:

update atmos_sites asites
set stationid = my.stationid
from my_stations my
where asites.id = my.atmos_site_id;

HTH

Bosco.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Salisbury 2013-05-31 23:27:24 Re: Using a CTE for an update
Previous Message David Salisbury 2013-05-31 22:33:36 Re: Using a CTE for an update