From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Roy Souther <roy@SiliconTao.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Insert race hazard condition.
Date: Tue, 25 Mar 2003 12:10:05 -0800 (PST)
Message-ID: <20030325120530.B43277-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <1048622477.2643.44.camel@UtopiaPlanetia.Ept>
On 25 Mar 2003, Roy Souther wrote:
> First of all I am a programmer not an DBA expert.
>
> There seems to be many ways to solve this. My first idea would be if I
> could make the INSERT some how return the index+1 that it creates but I
> can not find any way to make that work.
>
> My current idea is to have a short function that does both steps then
> returns the index value. This works and I think it should not cause any
> race hazard because the SQL execution should be completed before it
> returns to the program.
I think that it won't be guaranteed to work unless you lock the table.
> Is there a better way to do this? How do DBAs with a lot of connections
> safely create new records?
You might want to look at using a sequence to do your number generation.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sszabo@megazone23.bigpanda.com, roy@SiliconTao.com
Subject: Re: Insert race hazard condition.
In-Reply-To: <20030325120530.B43277-100000@megazone23.bigpanda.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox