Re: Using curr_val Wisely

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Using curr_val Wisely
Дата
Msg-id 23599.963422577@sss.pgh.pa.us
обсуждение исходный текст
Ответ на RE: Using curr_val Wisely  ("Andrew Snow" <als@fl.net.au>)
Список pgsql-general
"Andrew Snow" <als@fl.net.au> writes:
>> I'm using curr_val('blah_id_seq') in a transaction like so: (in
>> pseudo SQL)

> curr_val() returns the current value of the sequence, in the current
> transaction.

More precisely, currval() returns the same value returned by the most
recent nextval() on that sequence in the current backend --- transaction
boundaries don't matter AFAIR.

If you try currval() without ever having executed nextval() in the
current session, you will see this is so.

(I believe a setval() also causes currval() to become set, but that's
a special case that seldom matters.)

So you need not worry about other backends when using currval().  If you
have rules or triggers that can cause the sequence to get advanced, then
you could get confusing results if you forget these rules/triggers are
being fired.

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [NOVICE] newbie problem on creating table
Следующее
От: Jeff Waugh
Дата:
Сообщение: Re: Re: [INTERFACES] Re: Link to postgesql components