From: Peter Atkins <peter.atkins@NXCD.com>
To: Ken Corey <ken.corey@atomic-interactive.com>
Cc: 'pgsql-sql@postgresql.org' <pgsql-sql@postgresql.org>
Subject: Re: Returning PK of first insert for second insert use.
Date: Mon, 29 Jul 2002 13:20:01 -0700
Message-ID: <1CAD483B723BD611B0C10090274FF0685547CC@NXCDMAIL> (raw)
Thank you for explaining that in detail it makes sense now. I'll give it a
try.
Thanks again!
-p
-----Original Message-----
From: Ken Corey [mailto:ken.corey@atomic-interactive.com]
Sent: Monday, July 29, 2002 1:05 PM
To: Peter Atkins
Cc: 'pgsql-sql@postgresql.org'
Subject: RE: Returning PK of first insert for second insert use.
On Mon, 2002-07-29 at 20:52, Peter Atkins wrote:
> Is there a possibility of another application accessing the DB and using
the
> id before my function has completed the transaction? I'm concerned with
the
> possibility of cross-over of ID's if the insert hangs.
>
> There's no way to return the id of that insert inherently, and then use it
> for the second insert? I think SQL uses something like ADD_ID, not sure.
That's the beauty of the nextval statement. The database internally
sequences requests to it so that you're kept out of harm's way.
Say process A called the function,and nextval returns 16. The function
now continues on its way, but is not finished when process B then calls
the function (before A is done), and nextval returns 17.
So, then function called by process A returns 16, and the function
called by process B returns 17.
That means that unless the results of process B depend in some way upon
the results of process A, there's no problem.
-Ken
--
Ken Corey CTO http://www.atomic-interactive.com 07720 440 731
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: peter.atkins@NXCD.com, ken.corey@atomic-interactive.com
Subject: Re: Returning PK of first insert for second insert use.
In-Reply-To: <1CAD483B723BD611B0C10090274FF0685547CC@NXCDMAIL>
* 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