How to define operator class for composite type in PostgreSQL?

415 views Asked by At

I have a composite type. And I want to define exclusion constraint on it, that would also be combined with range exclusions, but getting the following error.


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

How can I define the operator class for 'example_t' composite type?

1

There are 1 answers

2
Laurenz Albe On

It is complicated to define a new GiST operator class. You'd have to define support functions and matching strategies. See the documentation for an example how that is done using C functions.

But I think it would be much simpler not to include the column of type example_t in the exclusion constraint, but the individual elements id.x and id.y. That way you can probably get along with the operator classes defined in the btree_gist contrib module.