pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Jean-Luc Lachance <jllachan@sympatico.ca>
To: pgsql-sql@postgresql.org
Cc: Markus Bertheau <twanger@bluetwanger.de>
Subject: Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo
Date: Tue, 17 Aug 2004 11:54:14 -0400
Message-ID: <41222A26.1080204@sympatico.ca> (raw)
In-Reply-To: <1092752492.2627.23.camel@dicaprio.akademie1.de>
References: <1092740863.2627.17.camel@dicaprio.akademie1.de>
<20040817141229.GA15770@wolff.to>
<1092752492.2627.23.camel@dicaprio.akademie1.de>
If your intent is to insert a new record with position incremented by 1,
you should use a trigger. Look at the autoincrement thread from few days
ago.
Markus Bertheau wrote:
> В Втр, 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
>
view thread (8+ messages) latest in thread
Message-ID: <41222A26.1080204@sympatico.ca> Permalink: ../41222A26.1080204@sympatico.ca/ Also on: postgresql.org/message-id/41222A26.1080204@sympatico.ca ·
reply
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Reply to all the recipients using the --to and --cc options: reply via email To: pgsql-sql@postgresql.org Cc: jllachan@sympatico.ca, twanger@bluetwanger.de Subject: Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo In-Reply-To: <41222A26.1080204@sympatico.ca> * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox