X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 59FC45288A for ; Wed, 17 Aug 2005 09:56:04 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74491-10 for ; Wed, 17 Aug 2005 12:56:02 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 136F152854 for ; Wed, 17 Aug 2005 09:56:00 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j7HCu15P006519 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 17 Aug 2005 06:56:03 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j7HCu0uF019268; Wed, 17 Aug 2005 06:56:00 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j7HCu0U6019267; Wed, 17 Aug 2005 06:56:00 -0600 (MDT) (envelope-from mfuhr) Date: Wed, 17 Aug 2005 06:56:00 -0600 From: Michael Fuhr To: "josh@segrestfarms.com" Cc: Jason Minion , pgsql-admin@postgresql.org Subject: Re: SQL Help - Obtaining ID of record INSERTED Message-ID: <20050817125600.GA19186@winnie.fuhr.org> References: <0105A1BF505D304E9E5AF38B63E40E4E807FC2@EXCHANGE.siglercompanies.com> <43032FFA.5070108@segrestfarms.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43032FFA.5070108@segrestfarms.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.24 required=5 tests=[AWL=-0.230, TO_ADDRESS_EQ_REAL=0.47] X-Spam-Level: X-Archive-Number: 200508/215 X-Sequence-Number: 18534 On Wed, Aug 17, 2005 at 08:39:22AM -0400, josh@segrestfarms.com wrote: > You stated that the SELECT currval('orderid_id_seq') statement is a > separate query and must be treated as such. > > This gives me cause for concern. My intention is to obtain the orderid > of the order inserted at that moment, but if I am to use a separate > query it would seem there is a chance (albeit a small one) that another > order could come through before I am able to obtain the orderid. No, there isn't; or rather, it doesn't matter. See the documentation and the FAQ. http://www.postgresql.org/docs/8.0/interactive/functions-sequence.html Return the value most recently obtained by nextval for this sequence in the current session. (An error is reported if nextval has never been called for this sequence in this session.) Notice that because this is returning a session-local value, it gives a predictable answer whether or not other sessions have executed nextval since the current session did. http://www.postgresql.org/docs/faqs.FAQ.html#4.11.3 4.11.3) Doesn't currval() lead to a race condition with other users? No. currval() returns the current value assigned by your session, not by all sessions. -- Michael Fuhr