【问题标题】:How to define operator class for composite type in PostgreSQL?如何在 PostgreSQL 中为复合类型定义运算符类?
【发布时间】:2018-12-04 04:42:38
【问题描述】:

我有一个复合类型。我想在它上面定义排除约束,这也将与范围排除相结合,但得到以下错误。


create type example_t as (
    x uuid,
    y text
);

create table example (
    id example_t not null,
    time tstzrange not null,

    exclude using gist (id with =, time with &&)
);

ERROR: data type example_t has no default operator class for access method "gist" HINT: You must specify an operator class for the index or define a default operator class for the data type. SQL state: 42704

如何定义'example_t'复合类型的操作符类?

【问题讨论】:

    标签: postgresql composite-types range-types gist-index


    【解决方案1】:

    定义一个新的 GiST 操作符类很复杂。您必须定义 support functions 和匹配策略。请参阅the documentation 了解如何使用 C 函数完成此操作的示例。

    但我认为不将example_t 类型的列包含在排除约束中会简单得多,而是包含单个元素id.xid.y。这样你就可以和btree_gist contrib 模块中定义的运算符类相处融洽了。

    【讨论】:

    • 是的,这可能是我能做的最简单的。
    • 我只是希望有一种方法可以重用 uuid 和文本类的运算符来做到这一点。
    猜你喜欢
    • 1970-01-01
    • 2021-11-30
    • 2021-06-11
    • 2020-10-10
    • 2021-07-30
    • 2021-11-09
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多