PostgreSQL,获取所有分区的 table 名称和所有未分区的 table 名称

PostgreSQL, get all partitioned table names and all NOT partiotioned table names

如何获取数据库中所有未分区 table 的名称?我使用 PostgresSQL 9.6

以及如何仅获取分区 table 的名称?

现在我的数据库中有分区的名称,指定了一个 table 名称,但我需要动态地这样做。

SELECT i.inhrelid::regclass AS child
FROM   pg_inherits i
WHERE  i.inhparent = 'public.documento'::regclass;

已更新

对于分区表:

select distinct inhparent::regclass from pg_inherits

而不是像这样的分区:

select oid::regclass::text relation
from pg_class where relkind = 'r'
except
select distinct inhparent::regclass::text
from pg_inherits
except
select distinct inhrelid::regclass::text
from pg_inherits
;

注意:要过滤结果,只需使用where,如

with l as (
<code above>
)
select * from l where relation not like 'pg_%';

pg_inherits 记录有关 table 和索引继承层次结构的信息。 如果只需要获取所有分区的table(不包括分区索引),我们可以使用:

select relnamespace::regnamespace::text schema_name, oid::regclass::text table_name from pg_class
where relkind = 'p' and oid in (select distinct inhparent from pg_inherits)
order by schema_name, table_name;