Re: Update from same table - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Update from same table
Date
Msg-id 200402040928.08456.josh@agliodbs.com
Whole thread Raw
In response to Update from same table  (Jürgen Cappel <email@juergen-cappel.de>)
List 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.mycolumnWHERE 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 BerkusAglio Database SolutionsSan Francisco



pgsql-sql by date:

Previous
From: Jürgen Cappel
Date:
Subject: Update from same table
Next
From: "Raman"
Date:
Subject: TIME ZONE SQL