在postgresql数据库中跨边界查找分区

0pizxfdo  于 2022-12-18  发布在  PostgreSQL
关注(0)|答案(2)|浏览(125)

如何通过分区的范围(边界)信息在数据库目录中找到分区?我使用日期字段对表进行了分区,我需要通过该信息找到分区。我发现在目录“子”表中有一个“relpartbound”字段,但似乎不容易搜索。

bqucvtff

bqucvtff1#

SELECT
    nmsp_parent.nspname AS parent_schema,
    parent.relname      AS parent,
    nmsp_child.nspname  AS child_schema,
    child.relname       AS child,
    pg_get_expr(child.relpartbound, child.relfilenode) AS child_bounds
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
WHERE parent.relname = 'parent_table_name';

PostgreSQL函数“pg_get_expr”将反编译“child.relpartbound”表达式的内部形式,并将给予我一些更可读的东西,如:

FOR VALUES FROM ('2017-01-01') TO ('2017-01-02')

Ty @a_horse_with_no_name为伟大的建议。

vpfxa7rd

vpfxa7rd2#

应该是

pg_get_expr(child.relpartbound, child.oid)

代替

pg_get_expr(child.relpartbound, child.relfilenode)

相关问题