Re: [GENERAL] using ID as a key

From: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] using ID as a key
Date: 2000-02-07 20:10:08
Message-ID: 20000207141008.A24873@rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Feb 07, 2000 at 01:37:21PM -0600, Ed Loehr wrote:
> kaiq(at)realtyideas(dot)com wrote:
> >
> > and, it seems not "programmatically at all.
>
> What would make it "programmatic" in my view would be calling a
> function, as in "$newID = GetNewID()", prior to INSERT and then using
> the returned ID value in your INSERT, rather than using a 'default
> nextval' to get the value. I don't see why one wouldn't want to use a
> sequence object within GetNewID(), FWIW. But sounds like it is not
> the kind of programmatic example/explanation you were looking for...
>

In fact, that's exactly how a number of core psql developers recommend
handling the problem of how to get the new value just assigned by
a default nextval() clause: don't use the default, do:

$newID = SELECT nextval('my_ID_seq')

INSERT INTO my_table (my_id,somethng,otherthng) VALUES ($newID, $some, $other)

or equivalent, so you've already got the ID in hand.

Personally, I use the SELECT curval('seq_name') construct.

Ross

--
Ross J. Reedstrom, Ph.D., <reedstrm(at)rice(dot)edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St., Houston, TX 77005

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message kaiq 2000-02-07 21:34:35 Re: [GENERAL] using ID as a key
Previous Message Ed Loehr 2000-02-07 19:37:21 Re: [GENERAL] using ID as a key