获取继承 table 的父名称和架构

Get parent name and schema of a inherited table

假设我有一个名为 master.products 的 PostgreSQL table 和另一个名为 account.products 的 PostgreSQL table。第二个继承第一个。

是否可以创建查询以获取 table account.products 的父名称和架构?

您从系统目录中获取此信息 pg_inherits

SELECT inhparent::regclass::text
FROM   pg_catalog.pg_inherits
WHERE  inhrelid = 'account.product'::regclass;

根据当前 search_path 名称自动进行模式限定,使其明确无误。

SQL Fiddle.

相关:

  • Check if table inherits from other table in PostgreSQL

关于regclass

  • How to check if a table exists in a given schema