X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 38B319DCC97 for ; Thu, 23 Feb 2006 12:30:19 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03144-03 for ; Thu, 23 Feb 2006 12:30:10 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from peufeu.com (unknown [82.67.9.10]) by postgresql.org (Postfix) with ESMTP id 8A4E19DCC4C for ; Thu, 23 Feb 2006 12:30:07 -0400 (AST) Received: (qmail 22949 invoked from network); 23 Feb 2006 17:30:56 +0100 Received: from unknown (HELO apollo13) (82.67.9.10) by boutiquenumerique.com with SMTP; 23 Feb 2006 17:30:56 +0100 Date: Thu, 23 Feb 2006 17:30:55 +0100 To: mario.splivalo@mobart.hr, "Achilleus Mantzios" Subject: Re: 'locking' the SELECTs based on indices... Cc: pgsql-sql@postgresql.org References: <1140692542.5002.26.camel@localhost.localdomain> From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: In-Reply-To: <1140692542.5002.26.camel@localhost.localdomain> User-Agent: Opera M2/8.51 (Linux, build 1462) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.101 required=5 tests=[AWL=0.101] X-Spam-Score: 0.101 X-Spam-Level: X-Archive-Number: 200602/279 X-Sequence-Number: 24289 > 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.