Search Postgresql Archives

allocate chunk of sequence

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux