From: Michael J Davis <michael.j.davis@tvguide.com>
To: 'Herouth Maoz' <herouth@oumail.openu.ac.il>
To: emils@mail.usis.bkc.lv
To: pgsql-sql@postgreSQL.org
Subject: RE: [SQL] Getting primary key from insert statement
Date: Mon, 7 Jun 1999 15:10:26 -0500
Message-ID: <93C04F1F5173D211A27900105AA8FCFC14557B@lambic.prevuenet.com> (raw)
I have been using this technique for years in Oracle (select next value from
the primary key sequence and insert using this primary key). I like this
approach. I don't think a transaction is needed. Access97 definitely likes
this approach better because it wants to reselect the newly inserted record.
Without the primary key in the insert statement, the re-select can be very
slow and potentially fail because the re-select is only using values
provided in the insert statement. Retrieving the primary key after the
insert does not help Access97.
> -----Original Message-----
> From: Herouth Maoz [SMTP:herouth@oumail.openu.ac.il]
> Sent: Monday, June 07, 1999 1:29 AM
> To: emils@mail.usis.bkc.lv; pgsql-sql@postgreSQL.org
> Subject: Re: [SQL] Getting primary key from insert statement
>
> At 12:51 +0300 on 07/06/1999, Emils Klotins wrote:
>
>
> >
> > Wouldn't it be simpler just to SELECT the next value from the sequence
> >BEFORE the insert and
> > use it in the INSERT statement directly?
>
> Then you have to have a transaction around the two operations. And by the
> time you do the select, someone may lock the table where you insert. It's
> a
> potential for deadlock.
>
> Herouth
>
> --
> Herouth Maoz, Internet developer.
> Open University of Israel - Telem project
> http://telem.openu.ac.il/~herutma
>
>
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: michael.j.davis@tvguide.com, herouth@oumail.openu.ac.il, emils@mail.usis.bkc.lv
Subject: Re: [SQL] Getting primary key from insert statement
In-Reply-To: <93C04F1F5173D211A27900105AA8FCFC14557B@lambic.prevuenet.com>
References: <93C04F1F5173D211A27900105AA8FCFC14557B@lambic.prevuenet.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