【问题标题】:how to get detail information of a exclude constraint in PostgreSQL 10?如何在 PostgreSQL 10 中获取排除约束的详细信息?
【发布时间】:2019-12-30 09:21:21
【问题描述】:

我正在开发一个PostgreSQL的SQL客户端工具,想支持工具中的EXCLUDE约束功能,如何获取PostgreSQL 10中排除约束的详细信息?

我希望得到EXCLUDE约束的详细信息,比如名称/索引方法/元素/注释/缓冲区/where/deferrable/deferred等。

【问题讨论】:

    标签: postgresql constraints information-schema


    【解决方案1】:

    我将使用这个例子:

    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
    

    【讨论】:

      猜你喜欢
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 2021-01-20
      • 1970-01-01
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多