Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id E0F351337B99 for ; Wed, 24 Nov 2010 17:21:18 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 44767-09 for ; Wed, 24 Nov 2010 21:21:11 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 62AFE1337B8F for ; Wed, 24 Nov 2010 17:21:11 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oAOLLAYh021823; Wed, 24 Nov 2010 16:21:10 -0500 (EST) To: "Mikhail V. Puzanov" cc: pgsql-sql@postgresql.org Subject: Re: atomic multi-threaded upsert In-reply-to: <4CED72BB.3070905@gmail.com> References: <4CED72BB.3070905@gmail.com> Comments: In-reply-to "Mikhail V. Puzanov" message dated "Thu, 25 Nov 2010 02:16:59 +0600" Date: Wed, 24 Nov 2010 16:21:10 -0500 Message-ID: <21822.1290633670@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/54 X-Sequence-Number: 34792 "Mikhail V. Puzanov" writes: > -- increment and get the counter if exists > UPDATE sequences SET counter = counter + 1 > WHERE section = 'testSection' AND name = 'testKey' > RETURNING counter; Seems that what you have here is a bad manual implementation of a sequence. Why don't you use a real sequence object and nextval()? regards, tom lane