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?
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 elementsid.x
andid.y
. That way you can probably get along with the operator classes defined in thebtree_gist
contrib module.