Re: sequence

Поиск
Список
Период
Сортировка
От Andrew Perrin - Demography
Тема Re: sequence
Дата
Msg-id Pine.SUN.4.10.10004180916360.20063-100000@davis.DEMOG.Berkeley.EDU
обсуждение исходный текст
Ответ на sequence  ("Vladimir V. Zolotych" <gsmith@eurocom.od.ua>)
Список pgsql-admin
I figured this out recently with the help of the list - you want either
nextval() or currval().  In my case, I used currval().  Basically:

SELECT currval('table_field_seq');

will return the most recently assigned value to the field *by the current
backend* which means:

- There's no danger of a race condition (another user creating a record in
the time between your creating the record and calling currval); BUT
- You must be using the same backend as you did on the creation.

Hope this helps.

---------------------------------------------------------------------
Andrew J. Perrin - aperrin@demog.berkeley.edu - NT/Unix Admin/Support
Department of Demography    -    University of California at Berkeley
2232 Piedmont Avenue #2120  -    Berkeley, California, 94720-2120 USA
http://demog.berkeley.edu/~aperrin --------------------------SEIU1199

On Tue, 18 Apr 2000, Vladimir V. Zolotych wrote:

> Hello all
>
> What is the safe way to add record to a table
> and get it id (generated by a sequence) consistently?
>
> E.g.
> 1) add record (INSERT INTO...) to a table
> (the record's id will be generated
> automatically due the ``id SERIAL'' column were defined).
>
> 2) get the id of a just created record.
>
> Thanks
>
>
> --
> Vladimir Zolotych                         gsmith@eurocom.od.ua
>
>
>


В списке pgsql-admin по дате отправления:

Предыдущее
От: Margarita Barvinok
Дата:
Сообщение: Re: DEFAULT now() ?
Следующее
От: Loïc TREGOUËT
Дата:
Сообщение: Postquel?