X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id C4D8AD1D52E for ; Sun, 1 Feb 2004 19:59:14 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 85995-08 for ; Sun, 1 Feb 2004 15:59:14 -0400 (AST) Received: from seahorse.shentel.net (seahorse.shentel.net [204.111.11.44]) by svr1.postgresql.org (Postfix) with ESMTP id 49166D1D3BC for ; Sun, 1 Feb 2004 15:59:12 -0400 (AST) Received: from shentel.net (ha30s053.d.shentel.net [204.111.23.53]) by seahorse.shentel.net (8.11.7/8.11.7) with ESMTP id i11Jx1402160 for ; Sun, 1 Feb 2004 14:59:03 -0500 Message-ID: <401D5A61.9000509@shentel.net> Date: Sun, 01 Feb 2004 14:58:25 -0500 From: Paul & Natalie T User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-php@postgresql.org Subject: Re: LOCKing method in my situation? References: <62364058618.20040201153901@wenet.ru> In-Reply-To: <62364058618.20040201153901@wenet.ru> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/4 X-Sequence-Number: 2552 Alexander: It sounds like a lock preventing concurrent writes would be your best bet. This would mean that only one instance of your script can be *changing* the table at one time, but it has no effect on transactions that only read from that. If I read the docs correctly: http://www.postgresql.org/docs/7.4/static/explicit-locking.html You want to obtain a ROW EXCLUSIVE lock, e.g., LOCK TABLE IN ROW EXCLUSIVE; Regards, Paul Tillotson Alexander Popkov wrote: >Hello PostgreSQL gurus! > >I am have question to you. > >I am have table 'chall_item' in my database. >In many PHP scripts i am do 'SELECT * FROM chall_item....', but >in one script (join.php) i do > a) SELECT COUNT(*) FROM chall_item WHERE chall_no = XXX; > b) if returned number less then 10, then i do INSERT INTO chall_item (chall_no, ...) VALUES (XXX, ...); > >But if beetwen a) and b) other instance of 'join.php' do part "a)" - then odd row are added ;( > >I can do LOCK TABLE chall_item IN ACCESS EXCLUSIVE MODE, >but IMHO this is not true method in this situation, because i need lock only for 'join.php' >not for all scripts. Help me plz. Which other methods are exist in this situation. > > >