Re: Another weird one with an UPDATE - Mailing list pgsql-performance

From Stephan Szabo
Subject Re: Another weird one with an UPDATE
Date
Msg-id 20031011153251.F57866@megazone.bigpanda.com
Whole thread Raw
In response to Re: Another weird one with an UPDATE  (David Griffiths <dgriffiths@boats.com>)
List pgsql-performance
On Sat, 11 Oct 2003, David Griffiths wrote:

> Sorry - just found the FAQ (
> http://jamesthornton.com/postgres/FAQ/faq-english.html#4.22
> <http://jamesthornton.com/postgres/FAQ/faq-english.html#4.22> ) on how
> IN is very slow.
>
> So I rewrote the query:
>
> \o ./data/temp.txt
> SELECT current_timestamp;
> UPDATE user_account SET last_name = 'abc'
> WHERE EXISTS (SELECT ua.user_account_id FROM user_account ua,
> commercial_entity ce, commercial_service cs
> WHERE ua.user_account_id = ce.user_account_id AND
> ce.commercial_entity_id = cs.commercial_entity_id);
> SELECT current_timestamp;

I don't think that's the query you want.  You're not binding the subselect
to the outer values of user_account.

I think you want something like:
UPDATE user_account SET last_name = 'abc'
 WHERE EXISTS (SELECT 1 FROM commercial_entity ce, commercial_service cs
 WHERE user_account.user_account_id = ce.user_account_id AND
 ce.commercial_entity_id = cs.commercial_entity_id);

pgsql-performance by date:

Previous
From: David Griffiths
Date:
Subject: Re: Another weird one with an UPDATE
Next
From: Christopher Kings-Lynne
Date:
Subject: Re: go for a script! / ex: PostgreSQL vs. MySQL