Re: fetching the id of a new row
От | Richard Huxton |
---|---|
Тема | Re: fetching the id of a new row |
Дата | |
Msg-id | 3A864C03.A7561E33@archonet.com обсуждение исходный текст |
Ответ на | fetching the id of a new row (Jelle Ouwerkerk <jelle@openface.ca>) |
Список | pgsql-sql |
Albert REINER wrote: > > I do not know of a way to insert and select in one statement without > the use of a function (what's the problem with those, by the way?), > but as far as I can tell nextval() will return the next value for any > backend, so if you have more than one backend inserting at the same > time you might end up inserting with the same id twice. Instead you Actually nextval() works fine across backends. It always increments the sequence, so repeated calls waste numbers. > should insert once, without specifying the id (so that the default > value, which must be set to nextval()) will be used; to obtain the id, > if indeed you need it, you can than select currval(), which is > guaranteed to work on a per-backend basis. Yep - it's either get nextval and insert or insert and check currval. - Richard Huxton
В списке pgsql-sql по дате отправления: