3

我应该执行什么查询来获取继承的列?阅读了这篇综合文章后没有找到解决方案。

4

1 回答 1

4

如果我理解正确,您想知道作为表之间继承一部分的列的名称。

SELECT nmsp_parent.nspname    AS parent_schema,
       parent.relname         AS parent_table,
       nmsp_child.nspname     AS child_schema,
       child.relname          AS child_table,           
       column_parent.attname  AS column_parent_name
FROM pg_inherits
JOIN pg_class parent            ON pg_inherits.inhparent  = parent.oid
JOIN pg_class child             ON pg_inherits.inhrelid   = child.oid
JOIN pg_namespace nmsp_parent   ON nmsp_parent.oid        = parent.relnamespace
JOIN pg_namespace nmsp_child    ON nmsp_child.oid         = child.relnamespace
JOIN pg_attribute column_parent ON column_parent.attrelid = parent.oid
WHERE column_parent.attnum > 0
AND column_parent.attname NOT ILIKE '%pg.dropped%';

此查询显示作为层次结构一部分的列名。我希望你服务

于 2012-02-07T14:56:31.707 回答