Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo - Mailing list pgsql-sql

From Markus Bertheau
Subject Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo
Date
Msg-id 1092752492.2627.23.camel@dicaprio.akademie1.de
Whole thread Raw
In response to Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo  (Bruno Wolff III <bruno@wolff.to>)
Responses Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo  (Jean-Luc Lachance <jllachan@sympatico.ca>)
List pgsql-sql
В Втр, 17.08.2004, в 16:12, Bruno Wolff III пишет:
> > 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.

Can you detail an example where this wouldn't be good enough?

In a PL/pgSQL function I'm doing

PERFORM position FROM class_fields WHERE class = arg_class_name;
INSERT INTO class_fields (class, field, position) VALUES
(arg_class_name, arg_field_name, (SELECT MAX(position) FROM class_fields
WHERE class = arg_class_name));

Is this unsafe?

The question initially arose because I wanted to do something similar to

SELECT INTO var_new_position MAX(position) FROM class_fields WHERE class
= arg_class_name FOR UPDATE OF class_fields;

which didn't work.

Thanks

--
Markus Bertheau <twanger@bluetwanger.de>



pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo
Next
From: Jean-Luc Lachance
Date:
Subject: Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo