Re: [GENERAL] get the previous assigned sequence value

Поиск
Список
Период
Сортировка
От Stuart Rison
Тема Re: [GENERAL] get the previous assigned sequence value
Дата
Msg-id Pine.LNX.4.10.9912091243580.5807-100000@bsmlx17
обсуждение исходный текст
Ответ на Re: [GENERAL] get the previous assigned sequence value  ("Dev Elop" <dev@archonet.com>)
Список pgsql-general
On Thu, 9 Dec 1999, Dev Elop wrote:

> > >
> > > After an INSERT, I want to retrieve the value of the sequence I use for
> > > unique_ids
> > >
> ...
> >
> > Alternatively, use the currval(mytable_id_seq) function within the same
> > session immediately after the insert.
> >
> With this second method, you'd probably need to beware race conditions. If
> another process inserts a record into mytable after you do but before you
> call currval(), then you'll get the wrong value.
>
> Not an issue if you've only got one process accessing the table - probably
> is one if you have two or more.

I don't think that's true the currval belongs to the process (as it were)
so that what happens is that currval remains unchanged by inserts by other
processes.

nextval however is 'affected' meaning that nextval won't just return
curval+1, it returns whatever the next sequence item is taking into
account the increasses caused by other processes.

at least I seem to remember that from previous postings... any seconders?

Cheers,

S.

Stuart C. G. Rison
Department of Biochemistry and Molecular Biology
6th floor, Darwin Building, University College London (UCL)
Gower Street, London, WC1E 6BT, United Kingdom
Tel. 0207 504 2303, Fax. 0207 380 7193
e-mail: rison@biochem.ucl.ac.uk


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

Предыдущее
От: "Dev Elop"
Дата:
Сообщение: Re: [GENERAL] get the previous assigned sequence value
Следующее
От: Sascha Ziemann
Дата:
Сообщение: operator *=