From: Josh Berkus <josh@agliodbs.com>
To: Jürgen Cappel <email@juergen-cappel.de>
To: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: Update from same table
Date: Wed, 4 Feb 2004 09:28:08 -0800
Message-ID: <200402040928.08456.josh@agliodbs.com> (raw)
In-Reply-To: <JEEKIPNAKJNCFLMOBKHGOEDKDCAA.email@juergen-cappel.de>
References: <JEEKIPNAKJNCFLMOBKHGOEDKDCAA.email@juergen-cappel.de>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, email@juergen-cappel.de
Subject: Re: Update from same table
In-Reply-To: <200402040928.08456.josh@agliodbs.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox