Re: lastval(seq) ?

Поиск
Список
Период
Сортировка
От Christopher Browne
Тема Re: lastval(seq) ?
Дата
Msg-id 60smlmjnth.fsf@dev6.int.libertyrms.info
обсуждение исходный текст
Ответ на Re: lastval(seq) ?  ("scott.marlowe" <scott.marlowe@ihs.com>)
Список pgsql-general
cool_screen_name90001@yahoo.com (CSN) writes:
> For updating sequences after copy importing data (with
> id's).
>
> select setval('table_id_seq', (select max(id) from
> table));
>
> vs.
>
> select setval('table_id_seq', (select last_value from
> table_id_seq));
>
> Is there a transaction-safe way?

There's not likely to be.

For any given potential value of currval('table_id_seq'), it is always
possible that a transaction could be held open that is using that
value.

The only really _safe_ way to reset sequences is to do so when there
are no transactions active on the system.

In practice, we have to live with that potential for lack of safety,
and I would be inclined to set the value to the maximum visible value
plus some reasonable constant, say 1000, on the assumption that unless
someone is trying to do something actively pathologically bad, that
should be "good enough."

But my preference would be to do so with applications that might be
doing potentially-evil things SHUT DOWN.
--
output = ("cbbrowne" "@" "libertyrms.info")
<http://dev6.int.libertyrms.com/>
Christopher Browne
(416) 646 3304 x124 (land)

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

Предыдущее
От: "Ben Johnson"
Дата:
Сообщение: training on open source software
Следующее
От: frbn
Дата:
Сообщение: Re: Pgsql 7.3.3 on redhat 7.2