Re: Insert race hazard condition.

From: patrick <patrick+pgsql(at)boxsoft(dot)com>
To: Roy Souther <roy(at)SiliconTao(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Insert race hazard condition.
Date: 2003-03-25 20:32:03
Message-ID: 20030325123203.I255@3eye.boxsoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Good 2003-03-25 22:28:08 Concatenation Snafu
Previous Message Stephan Szabo 2003-03-25 20:10:05 Re: Insert race hazard condition.