Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id F2A7F9FA646 for ; Thu, 2 Nov 2006 18:07:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 81404-08 for ; Thu, 2 Nov 2006 18:07:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id B44B59FB2AF for ; Thu, 2 Nov 2006 18:07:41 -0400 (AST) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id A0A7E30DF4; Thu, 2 Nov 2006 23:07:40 +0100 (MET) From: "Bobus" X-Newsgroups: pgsql.sql Subject: fetching unique pins in a high-transaction environment... Date: 29 Oct 2006 08:36:48 -0800 Organization: http://groups.google.com Lines: 36 Message-ID: <1162139808.031657.23340@f16g2000cwb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: f16g2000cwb.googlegroups.com; posting-host=124.106.126.48; posting-account=OzfgeQ0AAAA5-_8F6HU0QheK-BteRp5f To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.835 tagged_above=0 required=5 tests=BAYES_40, DATE_IN_PAST_96_XX X-Spam-Level: * X-Archive-Number: 200611/67 X-Sequence-Number: 26719 Hi, I posted this question to the "general" forum, but then discovered this one which I think is more appropriate. Apologies for the cross-post. We are in the process of porting an application from SQL Server to PostgresQL. We have a table which contains a bunch of prepaid PINs. What is the best way to fetch the next available unique pin from the table in a high-traffic environment with lots of concurrent requests? For example, our PINs table might look like this and contain thousands of records. (FYI, the PIN numbers are generated by a third party and loaded into the table): ID PIN USED_BY DATE_USED .... 100 1864678198 101 7862517189 102 6356178381 .... 10 users request a pin at the same time. What is the easiest/best way to ensure that the 10 users will get 10 unique pins, while eliminating any waiting? SQL Server supports the notion of a SELECT FOR UPDATE with a READPAST hint which tells SQL Server to skip over locked rows instead of waiting until the lock is lifted. This guarantees a unique pin will be acquired every time without hampering performance. Is there any equivalent in Postgres? Any help would be greatly appreciated...