Re: UPDATE w/ subselect doing locking

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: David Ford <dford(at)erisksecurity(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: UPDATE w/ subselect doing locking
Date: 2001-11-15 14:58:27
Message-ID: 20011115065718.T7025-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 14 Nov 2001, David Ford wrote:

> Would someone mind setting my head on straight with a proper query
> please. Here is my table and the query I have thusfar. I need it to
> match and update specifically only the string I specify for the regex.
>
> bluelist=> select * from spamcontrol;
> id | logical group | count | add time | added
> by | regex | comment
> ----+---------------+-------+-------------------------------+----------------+-----------------------------------------------+---------
> | | 5 | 2001-11-12 00:09:41.326116-05 |
> 208.179.59.203 | MERCATI FINANZIARI |
> | | 5 | 2001-11-12 00:10:24.292267-05 |
> 208.179.59.203 | setup fees |
>
>
> bluelist=> UPDATE spamcontrol SET count=foo.count+1 FROM (SELECT count
> FROM spamcontrol WHERE regex='setup fees' FOR UPDATE) as foo;
>
> How do I get it to only update that one row?

Wouldn't update spamcontrol set count=count+1 where regex='setup fees';
do the same thing or am I missing something?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2001-11-15 14:59:53 Re: Serial data type not starting at 1
Previous Message tony 2001-11-15 14:53:46 Re: Serial data type not starting at 1