1

我有一个复合类型。我想对其定义排除约束,这也将与范围排除相结合,但会出现以下错误。


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”复合类型定义运算符类?

4

1 回答 1

2

定义一个新的 GiST 操作符类很复杂。您必须定义支持功能和匹配策略。有关如何使用 C 函数完成此操作的示例,请参阅文档。

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

于 2018-06-25T15:44:34.713 回答