我如何运行查询(在Postgresql内部表上)来检索部分索引的条件表达式(在本例中为roles_user_group_role_idx).
# \d roles Table "public.roles" Column | Type | Modifiers ---------------+-----------------------------+--------------------------------------- id | character varying(15) | not null default next_id('r'::bpchar) user_id | character varying(15) | not null group_id | character varying(15) | not null role | character varying(255) | not null language_code | character varying(2) | created_at | timestamp without time zone | not null updated_at | timestamp without time zone | not null Indexes: "roles_pkey" PRIMARY KEY,btree (id) "roles_user_group_role_idx" UNIQUE,btree (user_id,group_id,role) WHERE language_code IS NULL
根据PostgreSQL pg_index doc,pg_index.indpred似乎是我需要研究的领域.运行此查询:
SELECT C.oid,I.indpred FROM pg_catalog.pg_class C,pg_catalog.pg_namespace N,pg_catalog.pg_index I WHERE C.relname = 'roles_user_group_role_idx' AND C.relnamespace = N.oid AND I.indexrelid = C.oid AND N.nspname = 'public';
给了我这个,这不是那里.
oid | indpred ---------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1235504 | {NULLTEST :arg {VAR :varno 1 :varattno 5 :vartype 1043 :vartypmod 6 :varcollid 100 :varlevelsup 0 :varnoold 1 :varoattno 5 :location 95} :nulltesttype 0 :argisrow false}
我正朝着正确的方向前进吗?如何获取部分索引的WHERE子句?我正在使用PG 9.2
解决方法
好了一段谷歌搜索后我找到了答案
here,正确的查询:
SELECT C.oid,pg_get_expr(I.indpred,I.indrelid) FROM pg_catalog.pg_class C,pg_catalog.pg_index I WHERE C.relname = 'roles_user_group_role_idx' AND C.relnamespace = N.oid AND I.indexrelid = C.oid AND N.nspname = 'public';
结果:
oid | pg_get_expr ---------+------------------------- 1235504 | (language_code IS NULL)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。