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;