如何使用单个查询获取应用序列的所有序列和列
How to get all the sequences and columns to which sequence is applied using single query
我想在 PostgreSQL 中使用单个查询获取数据库中创建的所有序列、应用该序列的表和列。任何直接或间接的方法都有帮助。
SELECT t.relname as related_table, a.attname as related_column,s.relname as sequence_name
FROM pg_class s
JOIN pg_depend d ON d.objid = s.oid
JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid
JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)
JOIN pg_namespace n ON n.oid = s.relnamespace
WHERE s.relkind = 'S'
AND n.nspname = 'public'
我发现上面的查询将 return 表、列和相关序列的列表。
来源:http://www.dbforums.com/showthread.php?1667561-How-to-list-sequences-and-the-columns-by-SQL
我想在 PostgreSQL 中使用单个查询获取数据库中创建的所有序列、应用该序列的表和列。任何直接或间接的方法都有帮助。
SELECT t.relname as related_table, a.attname as related_column,s.relname as sequence_name
FROM pg_class s
JOIN pg_depend d ON d.objid = s.oid
JOIN pg_class t ON d.objid = s.oid AND d.refobjid = t.oid
JOIN pg_attribute a ON (d.refobjid, d.refobjsubid) = (a.attrelid, a.attnum)
JOIN pg_namespace n ON n.oid = s.relnamespace
WHERE s.relkind = 'S'
AND n.nspname = 'public'
我发现上面的查询将 return 表、列和相关序列的列表。
来源:http://www.dbforums.com/showthread.php?1667561-How-to-list-sequences-and-the-columns-by-SQL