Postgres: show inherited fields

孤街醉人 提交于 2019-12-06 02:21:33

If I understand correctly, you want to know the names of the columns that are part of an inheritance between tables.

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%';

This query displays the column name that is part of a hierarchy. I hope you serve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!