Re: What's the fastest way to do this?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Orion <o2(at)trustcommerce(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: What's the fastest way to do this?
Date: 2001-11-12 20:57:36
Message-ID: 20011112125042.Y75520-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Mon, 12 Nov 2001, Orion wrote:

> UPDATE test
> SET description = x.description
> FROM test AS rt, test_tmp AS x
> WHERE rt.code = x.code;

> So (A) is this a bug or (B) do I totally misunderstand that UPDATE statement
> above. I appears that it should update each row in table 'test' with the
> description corresponding to the code in test_tmp. If this is not the
> proper way to do this, what is?

The above update isn't doing what you're expecting. You're updating
test, you don't need the test as rt in the from unless you are attempting
a self-join.

Try:
update test
set description = x.description
from test_tmp as x
where test.code=x.code;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-11-12 21:28:27 Re: What's the fastest way to do this?
Previous Message J Smith 2001-11-12 20:41:48 Re: Sourceforge on Oracle?