Re: 'locking' the SELECTs based on indices... - Mailing list pgsql-sql

From PFC
Subject Re: 'locking' the SELECTs based on indices...
Date
Msg-id op.s5fphtpwcigqcu@apollo13
Whole thread Raw
In response to Re: 'locking' the SELECTs based on indices...  (Mario Splivalo <mario.splivalo@mobart.hr>)
List pgsql-sql

> 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.




pgsql-sql by date:

Previous
From: Mario Splivalo
Date:
Subject: Re: 'locking' the SELECTs based on indices...
Next
From: PFC
Date:
Subject: Re: 'locking' the SELECTs based on indices...