From: PFC <lists@peufeu.com>
To: mario.splivalo@mobart.hr, "Achilleus Mantzios" <achill@matrix.gatewaynet.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: 'locking' the SELECTs based on indices...
Date: Thu, 23 Feb 2006 17:30:55 +0100
Message-ID: <op.s5fphtpwcigqcu@apollo13> (raw)
In-Reply-To: <1140692542.5002.26.camel@localhost.localdomain>
References: <Pine.LNX.4.44.0602231349430.15710-100000@matrix.gatewaynet.com>
<1140692542.5002.26.camel@localhost.localdomain>
> I lock just that particular row, which is no good. I need to have all
> the codes for the service 1 locked, so if it happens that two users send
> the very same code, one has to fail. Therefore, from within plpgsql I
> first do:
I'm a bit tired tonight so I'll simplify your example :
CREATE TABLE stuff ( a INT, b INT );
Basically you want to lock ALL rows with a certain value of a, in order
to perform an operation on only one of them.
You could do this :
CREATE TABLE all_as ( a INT PRIMARY KEY )
CREATE TABLE stuff ( a INT REFERENCES all_as(a), b INT );
Now all the rows in "stuff" that have the same value of "a" reference the
same row in "all_as".
All you have to do is
SELECT * FROM all_as WHERE a=the value FOR UPDATE
and you lock all rows having that particular value of a in the big table.
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: lists@peufeu.com, achill@matrix.gatewaynet.com
Subject: Re: 'locking' the SELECTs based on indices...
In-Reply-To: <op.s5fphtpwcigqcu@apollo13>
* 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