X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D5F8311F8C2A for ; Tue, 18 Apr 2006 23:20:21 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0.203 X-Spam-Level: X-Spam-Status: No, score=0.203 required=5 tests=[AWL=0.203] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id gy00EJT0OVMM for ; Tue, 18 Apr 2006 23:20:13 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from houston.familyhealth.com.au (houston.au.fhnetwork.com [203.22.197.21]) by postgresql.org (Postfix) with ESMTP id DFFBB11F8BFA for ; Tue, 18 Apr 2006 23:20:16 -0300 (ADT) Received: from houston.familyhealth.com.au (localhost [127.0.0.1]) by houston.familyhealth.com.au (Postfix) with ESMTP id 3E02825308; Wed, 19 Apr 2006 10:20:14 +0800 (WST) Received: from [127.0.0.1] (work-40.internal [192.168.0.40]) by houston.familyhealth.com.au (Postfix) with ESMTP id E9CBF252E3; Wed, 19 Apr 2006 10:20:11 +0800 (WST) Message-ID: <44459EAF.2030601@calorieking.com> Date: Wed, 19 Apr 2006 10:21:35 +0800 From: Christopher Kings-Lynne User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: PFC Cc: Tom Lane , mario.splivalo@mobart.hr, pgsql-performance@postgresql.org Subject: Re: SELECT FOR UPDATE performance is bad References: <1145365720.18469.35.camel@localhost.localdomain> <13037.1145370658@sss.pgh.pa.us> <1145371662.31555.10.camel@localhost.localdomain> <13609.1145374386@sss.pgh.pa.us> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-familyhealth-MailScanner-Information: Please contact the ISP for more information X-familyhealth-MailScanner: Found to be clean X-familyhealth-MailScanner-From: chris.kings-lynne@calorieking.com X-Archive-Number: 200604/413 X-Sequence-Number: 18497 > Suppose you have a table codes : > ( > game_id INT, > code TEXT, > used BOOL NOT NULL DEFAULT 'f', > prize ... > ... > PRIMARY KEY (game_id, code) > ) > > Just UPDATE codes SET used='t' WHERE used='f' AND game_id=... AND > code=... > > Then check the rowcount : if one row was updated, the code was not > used yet. If no row was updated, the code either did not exist, or was > already used. You can use a stored procedure with exceptions no? Try this: http://www.postgresql.org/docs/8.1/interactive/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE Chris