Re: How to best grab a chunk of Ids from a sequence

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: How to best grab a chunk of Ids from a sequence
Дата
Msg-id 18275.1005848724@sss.pgh.pa.us
обсуждение исходный текст
Ответ на How to best grab a chunk of Ids from a sequence  ("Bryan White" <bryan@arcamax.com>)
Список pgsql-sql
"Bryan White" <bryan@arcamax.com> writes:
> My question is is there a way to grab 4 million IDs from a sequence without
> calling nextval once for each ID.  Note, this sequence is being actively
> drawn on by other processes.

I can't think of any really clean way, but you could do something like
select setval('seq', nextval('seq') + 4000000 + 100);

and then use the 4m IDs just before the returned value.  Because the
nextval and setval aren't an atomic operation, it's possible that
some other processes will get in and do nextval in between.  The extra
100 advance of the sequence should provide an adequate buffer for that
... but of course it could theoretically be insufficient...
        regards, tom lane


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

Предыдущее
От: "Bryan White"
Дата:
Сообщение: How to best grab a chunk of Ids from a sequence
Следующее
От: Jason Earl
Дата:
Сообщение: Re: INSERT question