跟进我之前的question's answer。
我需要编写脚本来改变我所有表的序列(100+)
下面给出的是表gcompany
alter sequence seq_gcompany_id owned by company.companyid;
如何针对所有Alter
获取此sequence
个查询?
提示 :所有序列名称均以seq_g
答案 0 :(得分:0)
试试这个。
Select 'alter sequence '||_seq||' owned by '||_table||'.'||_column||';' FROM (SELECT
n.nspname AS _schema,
c.relname AS _table,
a.attname AS _column,
SUBSTRING(d.adsrc FROM E'nextval\\(''([^'')]+)''') AS _seq
FROM pg_attrdef AS d
JOIN pg_attribute AS a ON a.attrelid = d.adrelid AND a.attnum = d.adnum
JOIN pg_class AS c ON c.oid = d.adrelid
JOIN pg_namespace AS n ON n.oid = c.relnamespace
WHERE adsrc LIKE 'nextval(''%') t;
并以pgScript
阅读 关于 pg_class 和 pg_attribute