我有一个名为seque_post的序列.
我需要找出它正在使用的表格.
有没有办法编写一个会给出表名的查询?
我写了这个查询来查找序列:
select * from pg_class where relname like 'seque_post'
有一个在那里提交reltoastrelid,根据manual给出:
OID of the TOAST table associated with this table,0 if none. The TOAST table stores large attributes “out of line” in a secondary table.
但我不知道如何从这里继续..建议?
解决方法
要查找序列与“相关”的表,您可以使用以下内容:
select seq_ns.nspname as sequence_schema,seq.relname as sequence_name,tab_ns.nspname as table_schema,tab.relname as related_table from pg_class seq join pg_namespace seq_ns on seq.relnamespace = seq_ns.oid JOIN pg_depend d ON d.objid = seq.oid AND d.deptype = 'a' JOIN pg_class tab ON d.objid = seq.oid AND d.refobjid = tab.oid JOIN pg_namespace tab_ns on tab.relnamespace = tab_ns.oid where seq.relkind = 'S' and seq.relname = 'seque_post' and seq_ns.nspname = 'public';
只是为了完成图片:
反过来(查找列的序列)更容易,因为Postgres有一个函数来查找列的序列:
select pg_get_serial_sequence('public.some_table','some_column');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。