Re: Update from same table

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Jürgen Cappel <email(at)juergen-cappel(dot)de>, "pgsql-sql" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Update from same table
Date: 2004-02-04 17:28:08
Message-ID: 200402040928.08456.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Jurgen,

> UPDATE a.mytable from b.mytable
> SET a.mycolumn = b.mycolumn
> WHERE a.firstid = some_key
> AND b.firstid = some_other_key
> AND a.secondaryid = b.secondaryid;

Very close, actually; you just need to fix the table alias:

UPDATE mytable
FROM mytable as b
SET mytable.mycolumn = b.mycolumn
WHERE mytable.firstid = some_key
AND b.firstid = some_other_key
AND mytable.secondaryid = b.secondaryid;

AFAIK, one can't alias a table name in an UPDATE clause. So for that instance
of the table, you need to use the full name.

--
-Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Raman 2004-02-04 17:57:20 TIME ZONE SQL
Previous Message Jürgen Cappel 2004-02-04 16:46:19 Update from same table