-3

我想使用 PostgreSQL 中的单个查询来获取在数据库中应用该序列的所有序列、表和列。任何直接或间接的方法都是有帮助的。

4

1 回答 1

0
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'

我发现上面的查询将返回表、列和相关序列的列表。

来源:http ://www.dbforums.com/showthread.php?1667561-How-to-list-sequences-and-the-columns-by-SQL

于 2016-08-01T06:35:03.500 回答