Postgres:显示继承的字段

发布于 2025-01-03 07:57:04 字数 122 浏览 5 评论 0原文

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

What query should I implement to get columns that are inherited? Having read this comprehensive post didn't find the solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回梦 2025-01-10 07:57:04

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

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文