X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 2B8C29FB1E8 for ; Fri, 7 Jul 2006 15:26:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 12959-09 for ; Fri, 7 Jul 2006 15:26:19 -0300 (ADT) X-Greylist: delayed 00:19:02.931964 by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id 74E2A9FB1DF for ; Fri, 7 Jul 2006 15:26:18 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 4D2AA3519F; Fri, 7 Jul 2006 11:07:10 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 4B2B835189; Fri, 7 Jul 2006 11:07:10 -0700 (PDT) Date: Fri, 7 Jul 2006 11:07:10 -0700 (PDT) From: Stephan Szabo To: Michael Glaesemann Cc: "Weber, Johann (ISS Kassel)" , pgsql-sql@postgresql.org Subject: Re: Atomar SQL Statement In-Reply-To: <279E27B5-183F-4520-BC43-A726A50646EF@seespotcode.net> Message-ID: <20060707105847.J77811@megazone.bigpanda.com> References: <279E27B5-183F-4520-BC43-A726A50646EF@seespotcode.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/109 X-Sequence-Number: 25683 On Fri, 7 Jul 2006, Michael Glaesemann wrote: > > On Jul 7, 2006, at 7:55 , Weber, Johann (ISS Kassel) wrote: > > > My concern: in a multi threaded environment, can a second thread > > interrupt this statement and eventually insert the same email > > address in > > the table with a different id? Or is this statement atomar? > > You're safe. Take a look at the FAQ entries on SERIAL: > > http://www.postgresql.org/docs/faqs.FAQ.html#item4.11.2 I don't think he is, because I don't think the issue is the SERIAL behavior, but instead the NOT EXISTS behavior. Won't the NOT EXISTS in read committed potentially be true for both concurrent sessions if the second happens before the first commits, which then would mean that both sessions will go on to attempt the insert (with their own respective ids from the serial)? Without a unique constraint on email I think he can end up with the same email address with two different ids.