Re: [GENERAL] using ID as a key
От | Ross J. Reedstrom |
---|---|
Тема | Re: [GENERAL] using ID as a key |
Дата | |
Msg-id | 20000207141008.A24873@rice.edu обсуждение исходный текст |
Ответ на | Re: [GENERAL] using ID as a key (Ed Loehr <eloehr@austin.rr.com>) |
Ответы |
Re: [GENERAL] using ID as a key
|
Список | pgsql-general |
On Mon, Feb 07, 2000 at 01:37:21PM -0600, Ed Loehr wrote: > kaiq@realtyideas.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@rice.edu> NSBRI Research Scientist/Programmer Computer and Information Technology Institute Rice University, 6100 S. Main St., Houston, TX 77005
В списке pgsql-general по дате отправления: