| From: | PFC <lists(at)peufeu(dot)com> |
|---|---|
| To: | mario(dot)splivalo(at)mobart(dot)hr, "Achilleus Mantzios" <achill(at)matrix(dot)gatewaynet(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: 'locking' the SELECTs based on indices... |
| Date: | 2006-02-23 16:30:55 |
| Message-ID: | op.s5fphtpwcigqcu@apollo13 |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | PFC | 2006-02-23 16:35:21 | Re: 'locking' the SELECTs based on indices... |
| Previous Message | Mario Splivalo | 2006-02-23 11:02:22 | Re: 'locking' the SELECTs based on indices... |