Re: UPDATE w/ subselect doing locking

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: David Ford <david(at)blue-labs(dot)org>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: UPDATE w/ subselect doing locking
Date: 2001-11-15 19:29:48
Message-ID: 20011115112703.E9260-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 15 Nov 2001, David Ford wrote:

> Yes, I know that works. I want to figure out how to use SELECT ... FOR
> UPDATE with UPDATE because I will have a need to lock these certain rows
> and do a bit more than just 'count'.
>
> >>bluelist=> UPDATE spamcontrol SET count=foo.count+1 FROM (SELECT count
> >>FROM spamcontrol WHERE regex='setup fees' FOR UPDATE) as foo;

In general the problem you're running into in your query is that you're
not specifying which values in foo go with which values in spamcontrol.
You're not limiting the update to only the rows that have 'setup fees'
you're updating all rows with a value from the row that has 'setup fees'.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew G. Hammond 2001-11-15 19:29:58 Re: Bug?
Previous Message Mihai Gheorghiu 2001-11-15 19:14:23 Replication