Re: update and IN vs. EXISTS

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: pginfo <pginfo(at)t1(dot)unisoftbg(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: update and IN vs. EXISTS
Date: 2003-02-01 14:54:12
Message-ID: 20030201145412.GA29037@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sat, Feb 01, 2003 at 12:40:00 +0100,
pginfo <pginfo(at)t1(dot)unisoftbg(dot)com> wrote:
>
> If I try to execute:
> update Table1 set fieldForUpdate = 1 where ID IN (select T2.ID from
> Table2);
> it is running very slow.

You might try:
update Table1 set fieldForUpdate = 1 from Table2 where Table1.id = Table2.id;

This uses a nonstandard postgres extension and may not be portable, if that
is a concern.

INs are being speeded up in 7.4, so the original form might work a lot better
in the next release.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ross J. Reedstrom 2003-02-01 23:42:03 Re: Controlling access to Sequences
Previous Message D'Arcy J.M. Cain 2003-02-01 14:16:08 Re: vacuum and serial primary keys