t=# do
$$
declare
_r record;
_t text;
begin
for _r in (select relname,relnamespace::regnamespace from pg_class where relname like '%_id_seq') loop
execute format('select last_value from %I.%I',_r.relnamespace,_r.relname) into _t;
raise info '%', 'seq: '||_r.relname||', last_value: '||_t;
end loop;
end;
$$
;
INFO: seq: test_table_id_seq, last_value: 3
INFO: seq: json_test_id_seq, last_value: 4
INFO: seq: test_a_id_seq, last_value: 1
INFO: seq: customer_id_seq, last_value: 4
INFO: seq: customerstatus_recordid_seq, last_value: 8
INFO: seq: customerstatus_id_seq, last_value: 1
INFO: seq: t1_id_seq, last_value: 16
INFO: seq: s100_serial_id_seq, last_value: 8
INFO: seq: t2_id_seq, last_value: 4
DO
也與未來10,there will be pg_sequence
也regnamespace
帶有9.5以前的版本加入對pg_namespace.oid
爲什麼你需要從序列LAST_VALUE?你可以從表中得到last_value – Exprator