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 93AEDD1D286 for ; Sun, 1 Feb 2004 15:42:01 +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 14634-10 for ; Sun, 1 Feb 2004 11:42:03 -0400 (AST) Received: from hal.kabsi.at (strange.kabsi.at [195.202.128.71]) by svr1.postgresql.org (Postfix) with ESMTP id C2819D1C9BA for ; Sun, 1 Feb 2004 11:41:57 -0400 (AST) Received: from cybertec.at (h062040243020.plc.cm.kabsi.at [62.40.243.20]) by hal.kabsi.at (8.11.1/) with ESMTP id i11FfTS0001905195; Sun, 1 Feb 2004 16:41:33 +0100 (CET) Message-ID: <401D1E44.9040408@cybertec.at> Date: Sun, 01 Feb 2004 16:41:56 +0100 From: =?ISO-8859-1?Q?Hans-J=FCrgen_Sch=F6nig?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Alexander Popkov Cc: 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=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/2 X-Sequence-Number: 2550 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. > If I understand you question correctly you have to use a SERIALIZABLE transaction to make sure that you can see the same snapshot during your transaction. Regards, Hans -- Cybertec Geschwinde u Schoenig Schoengrabern 134, A-2020 Hollabrunn, Austria Tel: +43/2952/30706 or +43/664/233 90 75 www.cybertec.at, www.postgresql.at, kernel.cybertec.at