gpt4 book ai didi

sql - 获取 PostgreSQL 数据库中的分区数

转载 作者:行者123 更新时间:2023-11-29 11:38:12 25 4
gpt4 key购买 nike

获取数据库中创建的分区数的最有效方法是什么?

我正在为 C++ 使用 PostgreSQL API。

最佳答案

这是您可以选择表分区的所有名称的方法:

SELECT
nmsp_parent.nspname AS parent_schema,
parent.relname AS parent,
nmsp_child.nspname AS child,
child.relname AS child_schema
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

它也可以用来计数:

SELECT
nmsp_parent.nspname AS parent_schema,
parent.relname AS parent,
COUNT(*)
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
GROUP BY
parent_schema,
parent;

关于sql - 获取 PostgreSQL 数据库中的分区数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8634144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com