pg_get_partkeydef() 是一个系统函数,用于返回分区键的定义。
pg_get_partkeydef() 在 PostgreSQL 10 中被添加。
用法
pg_get_partkeydef (tableoid) →text
pg_get_partkeydef() 以文本形式提取 pg_partitioned_table 中包含的分区键定义。
如果指定的关系不是一个分区表,则返回 NULL。如果指定的关系不存在,则会引发一个 ERROR。
请注意,在 PostgreSQL 16 之前,pg_get_partkeydef() 没有被文档化。
变更历史
- PostgreSQL 16
- 已添加文档(提交 422f86a8)
- PostgreSQL 10
- 已添加(提交 f0e44751)
示例
pg_get_partkeydef() 的基本用法示例
postgres=# CREATE TABLE hash_partition_table ( id INT NOT NULL, val TEXT ) PARTITION BY HASH (id); CREATE TABLE postgres=# SELECT pg_get_partkeydef('hash_partition_table'::regclass); pg_get_partkeydef ------------------- HASH (id) (1 row)
将 pg_get_partkeydef() 用于一个未分区的表
postgres=# SELECT pg_get_partkeydef('foo'::regclass) IS NULL;
?column?
----------
t
(1 row)
如果指定的表不存在,则会引发一个 ERROR。
postgres=# SELECT pg_get_partkeydef('non_such_table'::regclass);
ERROR: relation "non_such_table" does not exist
LINE 1: SELECT pg_get_partkeydef('non_such_table'::regclass);
参考资料
- PostgreSQL 文档: 系统目录信息函数
