I would like to use a GIN index on uuid[]
(to have efficient membership tests for arrays of uuids). However when I try it PostgreSQL gives me an error:
mydb=> CREATE TABLE foo (val uuid[]);
CREATE TABLE
mydb=> CREATE INDEX foo_idx ON foo USING GIN(val);
ERROR: data type uuid[] has no default operator class for access method "gin"
HINT: You must specify an operator class for the index or define a default operator class for the data type.
How can I add the necessary operator class so that it works?
Note that this is a similar question for the type citext
but the provided answer doesn't work.
As of PostgreSQL 10 the custom operator class _uuid_ops
is no longer necessary as there is now a general built-in opclass array_ops
on anyarry
(see: https://www.postgresql.org/docs/current/gin.html#GIN-BUILTIN-OPCLASSES)