Search Postgresql Archives

Locking to restrict rowcounts.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Consider the following scenario:

CREATE FUNCTION test(name)
select into cnt count(id) from items where owner = name;
--suppose someone inserts during this point? then next check will succeed when it should not.
if (cnt < 10) then
   insert into items values ('new item', name);
end;
end;

What is the best way to stop this function from entering too many items in a concurrent context? I think a lock is needed, although I'm not sure which would be most appropriate since the count requires the whole table (or at least no adds to have occurred I think I read something about predicate locking which sounds relevant but isn't supported in PostgreSQL. Ideally I want some kind of lock only relevant to "name" above.

Any strategies to deal with this?

Shak

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux