pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: patrick <patrick+pgsql@boxsoft.com>
To: Roy Souther <roy@SiliconTao.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Insert race hazard condition.
Date: Tue, 25 Mar 2003 12:32:03 -0800
Message-ID: <20030325123203.I255@3eye.boxsoft.com> (raw)
In-Reply-To: <1048622477.2643.44.camel@UtopiaPlanetia.Ept>
References: <1048622477.2643.44.camel@UtopiaPlanetia.Ept>
On Tue, Mar 25, 2003 at 01:01:17PM -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.
>
> When I add a record to a table I would do it in two steps.
> INSERT INTO mytable SELECT MAX(index)+1 FROM mytable
> SELECT MAX(index) FROM mytable
You probably want to call:
Oid oid = PQoidValue( res ); /* assuming C interface */
And use:
sprintf( sql, "select index from mytable where oid = %lu", oid );
instead of your second SQL statement.
[dd]
sidster
--
They who would sacrifice freedom for security will have neither.
-Ben Franklin
view thread (4+ messages)
Message-ID: <20030325123203.I255@3eye.boxsoft.com> Permalink: ../20030325123203.I255@3eye.boxsoft.com/ Also on: postgresql.org/message-id/20030325123203.I255@3eye.boxsoft.com ·
reply
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: patrick+pgsql@boxsoft.com, roy@SiliconTao.com Subject: Re: Insert race hazard condition. In-Reply-To: <20030325123203.I255@3eye.boxsoft.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