Re: 'locking' the SELECTs based on indices...
| От | PFC |
|---|---|
| Тема | Re: 'locking' the SELECTs based on indices... |
| Дата | |
| Msg-id | op.s5fphtpwcigqcu@apollo13 обсуждение исходный текст |
| Ответ на | Re: 'locking' the SELECTs based on indices... (Mario Splivalo <mario.splivalo@mobart.hr>) |
| Список | 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 по дате отправления: