debugsqlCritical
PostgreSQL EXCLUDE USING error: Data type integer has no default operator class
Viewed 0 times
postgresqlerrorclassoperatortypehasdefaultusingdatainteger
Problem
In PostgreSQL 9.2.3 I am trying to create this simplified table:
But I get this error:
The PostgreSQL docs use this example which does not work for me:
Same error message.
And this one, which does not work for me either:
Same error message.
I am able to create this without any problem:
and this:
I've spent quite a bit of time searching for hints about figuring out how to make this work, or figuring out why it won't work. Any ideas?
CREATE TABLE test (
user_id INTEGER,
startend TSTZRANGE,
EXCLUDE USING gist (user_id WITH =, startend WITH &&)
);But I get this error:
ERROR: data type integer 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.The PostgreSQL docs use this example which does not work for me:
CREATE TABLE room_reservation (
room text,
during tsrange,
EXCLUDE USING gist (room WITH =, during WITH &&)
);Same error message.
And this one, which does not work for me either:
CREATE TABLE zoo (
cage INTEGER,
animal TEXT,
EXCLUDE USING gist (cage WITH =, animal WITH <>)
);Same error message.
I am able to create this without any problem:
CREATE TABLE test (
user_id INTEGER,
startend TSTZRANGE,
EXCLUDE USING gist (startend WITH &&)
);and this:
CREATE TABLE test (
user_id INTEGER,
startend TSTZRANGE,
EXCLUDE USING btree (user_id WITH =)
);I've spent quite a bit of time searching for hints about figuring out how to make this work, or figuring out why it won't work. Any ideas?
Solution
Install the additional module
You can use the
on plain scalar data types, which can then be combined with range
exclusions for maximum flexibility. For example, after
installed, the following constraint will reject overlapping ranges
only if the meeting room numbers are equal:
In modern PostgreSQL you only need to run (once per database):
You need to have the "contrib" package installed in your OS first. Details depend on your OS and the software repository used. For the Debian family it's typically
btree_gist as is mentioned in the manual at the location you linked to:You can use the
btree_gist extension to define exclusion constraintson plain scalar data types, which can then be combined with range
exclusions for maximum flexibility. For example, after
btree_gist isinstalled, the following constraint will reject overlapping ranges
only if the meeting room numbers are equal:
In modern PostgreSQL you only need to run (once per database):
CREATE EXTENSION btree_gist;You need to have the "contrib" package installed in your OS first. Details depend on your OS and the software repository used. For the Debian family it's typically
postgresql-contrib-13 (for Postgres 13). Or just postgresql-contrib for the Red Hat family. Consider this related answer on SO:- Error when creating unaccent extension on PostgreSQL
Code Snippets
CREATE EXTENSION btree_gist;Context
StackExchange Database Administrators Q#37351, answer score: 52
Revisions (0)
No revisions yet.