我正在使用“ALTER SEQUENCE sequence OWNED by table.column”来改变Postgres中的序列关联。有没有办法使用\ ds或类似的东西查看这些新信息? \ ds仍然将表所有者显示为序列所有者。
答案 0 :(得分:3)
OWNED BY table.column
更改关联列; OWNER TO newowner
更改拥有序列的角色。所有者角色是\ds
中显示的内容。我不知道psql
命令来查看序列的链接列。 OWNED BY主要用于在删除引用列时级联删除相关序列。
您可以通过构建针对系统目录表pg_class,pg_depend和pg_attribute的查询来了解所拥有的列。我不确定pg_depend的所有确切语义,但是这个查询应该显示序列的列依赖性:
select tab.relname as tabname, attr.attname as column
from pg_class as seq
join pg_depend as dep on (seq.relfilenode = dep.objid)
join pg_class as tab on (dep.refobjid = tab.relfilenode)
join pg_attribute as attr on (attr.attnum = dep.refobjsubid and attr.attrelid = dep.refobjid)
where seq.relname = 'sequence';
答案 1 :(得分:3)
SELECT c.relname,u.usename
FROM pg_class c, pg_user u
WHERE c.relowner = u.usesysid and c.relkind = 'S'
AND relnamespace IN (
SELECT oid
FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%'
AND nspname != 'information_schema'
);