tww
.tww_app
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
reset_od_seqval()
Parameters
Name
Type
Mode
IN
Definition
DECLARE tbl_name text; rgx text; BEGIN BEGIN FOR tbl_name,rgx IN ( SELECT dot.tablename,pfx.prefix||dot.shortcut_en FROM information_schema.sequences seq LEFT JOIN tww_sys.dictionary_od_table dot ON seq.sequence_name = 'seq_'||dot.tablename||'_oid' LEFT JOIN (SELECT prefix FROM tww_sys.oid_prefixes WHERE active) pfx on True WHERE seq.sequence_schema = 'tww_od' AND dot.tablename IS NOT NULL) LOOP EXECUTE FORMAT('SELECT SETVAL(''tww_od.seq_%1$I_oid'',(SELECT max(seqs) FROM( SELECT RIGHT(obj_id, 6)::int as seqs FROM tww_od.%1$I WHERE regexp_match(obj_id, ''%2$s\d{6}$'') IS NOT NULL UNION SELECT last_value as seqs FROM tww_od.seq_%1$I_oid)foo));',tbl_name,rgx); END LOOP; END; END;