X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 81EFF475C98 for ; Tue, 25 Mar 2003 15:08:31 -0500 (EST) Received: from wolff.to (wolff.to [66.93.249.74]) by postgresql.org (Postfix) with SMTP id ACA0E474E44 for ; Tue, 25 Mar 2003 15:08:30 -0500 (EST) Received: (qmail 14349 invoked by uid 500); 25 Mar 2003 20:07:59 -0000 Date: Tue, 25 Mar 2003 14:07:59 -0600 From: Bruno Wolff III To: Roy Souther Cc: pgsql-sql@postgresql.org Subject: Re: Insert race hazard condition. Message-ID: <20030325200759.GB14216@wolff.to> Mail-Followup-To: Roy Souther , pgsql-sql@postgresql.org References: <1048622477.2643.44.camel@UtopiaPlanetia.Ept> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1048622477.2643.44.camel@UtopiaPlanetia.Ept> User-Agent: Mutt/1.3.25i X-Spam-Status: No, hits=-38.0 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/562 X-Sequence-Number: 12600 On Tue, Mar 25, 2003 at 13:01:17 -0700, Roy Souther wrote: > First of all I am a programmer not an DBA expert. > > For a long time now when I create a table I have an index field that is > of type int4 to be the primary key. All of the queries and activity on > each record uses this field to do the posting, manipulating and reading > of data to and from tables. [snip] > Is there a better way to do this? How do DBAs with a lot of connections > safely create new records? The short answer is to use sequences. Use currval to get the value assigned earlier in the same transaction.