allocate chunk of sequence

Поиск
Список
Период
Сортировка
От Gary Fu
Тема allocate chunk of sequence
Дата
Msg-id f4rlrp$22cc$1@news.hub.org
обсуждение исходный текст
Ответы Re: allocate chunk of sequence  (Scott Marlowe <smarlowe@g2switchworks.com>)
Список pgsql-general
hello,

I try to allocate a chunk of ids from a sequence with the following
proc.  However, if I don't use the 'lock lock_table', the proc may not
work when it runs at the same time by different psql sessions.  Is there
a better way without using the 'lock lock_table' ?

Thanks,
Gary

create or replace function proc_allocate_seq(int)
     returns int as $$

declare
     nNumberOfFiles          alias for $1;

     aFileId int;
     aNewFileId int;

begin

     lock lock_table;

     aFileId = nextval('aa_seq');

; sleep(3);    if you have the proc

     aNewFileId = setval('aa_seq', aFileId + nNumberOfFiles - 1);

     return aFileId;

end;
$$ language plpgsql;

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

Предыдущее
От: "Andrus"
Дата:
Сообщение: Re: how to speed up query
Следующее
От: "Andrus"
Дата:
Сообщение: Disable duplicate index creation