PostgreSQL迁库后序列号冲突
通过如下SQL
查询序列号,复制出需要drop
的行执行删除
SELECT 'DROP SEQUENCE "'||n.nspname||'"."'||c.relname||'";' FROM pg_class c
left join pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind ='S'
ORDER BY c.relname
删除序列号没有带seq1
的序列
with t(s) as(
SELECT 'DROP SEQUENCE "'||n.nspname||'"."'||c.relname||'";' FROM pg_class c
left join pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind ='S'
ORDER BY c.relname)
SELECT * from t where t.s not like '%seq1";';