postgresql - Wait for the sequence to get last_value -


i have query gives sequences nextval:

select c.oid::regclass, setval(c.oid, nextval(c.oid), false)  pg_class c  c.relkind = 's' 

but throws error on production database:

error:  cannot access temporary tables of other sessions 

i've created function last_value (to avoid setting sequence value) in post get max id of sequences in postgresql

that doesn't help.

is there way wait sequences finished without locking tables?

thats function

create type tp_sequencedetails (sequence_name text, last_value bigint);  create or replace function getsequenceswithdetails()   returns setof tp_sequencedetails   $body$     declare       returnrec tp_sequencedetails;       sequence_name text;     begin        sequence_name in (select c.oid::regclass pg_class c c.relkind = 's')       loop         returnrec in execute 'select ''' || sequence_name || ''', last_value ' || sequence_name         loop           return next returnrec;         end loop;       end loop;      end;   $body$ language plpgsql volatile cost 100 rows 1000; 

error: cannot access temporary tables of other sessions

in session you're creating temporary sequence. trying or set value sequence, it's not visible in current session. temporary table , sequence visible session creates object.

solution: keep temporary sequences out of query.

select  c.oid::regclass, setval(c.oid, nextval(c.oid), false)  pg_class c     join pg_namespace on pg_namespace.oid = relnamespace c.relkind = 's' , nspname not ilike 'pg_temp%'; 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -