Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Markus Bertheau <twanger(at)bluetwanger(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo
Date: 2004-08-17 14:12:29
Message-ID: 20040817141229.GA15770@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Aug 17, 2004 at 13:07:43 +0200,
Markus Bertheau <twanger(at)bluetwanger(dot)de> wrote:
> Hi,
>
> why is the following query not allowed:
>
> SELECT MAX(position) FROM (SELECT position FROM classes WHERE name =
> 'foo' FOR UPDATE OF classes) AS foo
>
> It's clear which rows should be locked here, I think.

Even if it was allowed, it probably wouldn't be good enough because it won't
protect against newly inserted records. You really want to lock the table
against concurrent updates when doing this if concurrent updates can cause
a problem. You really want predicate locking, to lock any old or new rows
with name = 'foo', but postgres doesn't have that capability.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Markus Bertheau 2004-08-17 14:21:32 Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo
Previous Message Elieser Leão 2004-08-17 13:48:49 Re: Verifying data type