如何获取 PostgreSQL 10 中排除约束的详细信息?
how to get detail information of a exclude constraint in PostgreSQL 10?
我正在开发一个SQL Postgre客户端工具SQL,想在工具中支持EXCLUDE约束功能,如何在Postgre中获取排除约束的详细信息SQL10?
我希望获得 EXCLUDE 约束的详细信息,如名称/索引方法/元素/注释/缓冲区/where/deferrable/deferred 等
我将使用这个例子:
CREATE TABLE xclude (id integer NOT NULL, EXCLUDE (id WITH =));
您可以使用这个查询:
SELECT c2.relname,
i.indisvalid,
pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),
pg_catalog.pg_get_constraintdef(con.oid, true),
contype,
condeferrable,
condeferred,
c2.reltablespace
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_index i ON c.oid = i.indrelid
JOIN pg_catalog.pg_class c2 On i.indexrelid = c2.oid
LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('x'))
WHERE c.oid = 'xclude'::regclass;
结果:
relname | xclude_id_excl
indisvalid | t
pg_get_indexdef | CREATE INDEX xclude_id_excl ON xclude USING btree (id)
pg_get_constraintdef | EXCLUDE USING btree (id WITH =)
contype | x
condeferrable | f
condeferred | f
reltablespace | 0
我正在开发一个SQL Postgre客户端工具SQL,想在工具中支持EXCLUDE约束功能,如何在Postgre中获取排除约束的详细信息SQL10?
我希望获得 EXCLUDE 约束的详细信息,如名称/索引方法/元素/注释/缓冲区/where/deferrable/deferred 等
我将使用这个例子:
CREATE TABLE xclude (id integer NOT NULL, EXCLUDE (id WITH =));
您可以使用这个查询:
SELECT c2.relname,
i.indisvalid,
pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),
pg_catalog.pg_get_constraintdef(con.oid, true),
contype,
condeferrable,
condeferred,
c2.reltablespace
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_index i ON c.oid = i.indrelid
JOIN pg_catalog.pg_class c2 On i.indexrelid = c2.oid
LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('x'))
WHERE c.oid = 'xclude'::regclass;
结果:
relname | xclude_id_excl
indisvalid | t
pg_get_indexdef | CREATE INDEX xclude_id_excl ON xclude USING btree (id)
pg_get_constraintdef | EXCLUDE USING btree (id WITH =)
contype | x
condeferrable | f
condeferred | f
reltablespace | 0