4

Whenever I try to try to create a GIST index on text[], I get the above error.

CREATE TABLE bar(f)
AS VALUES
  (ARRAY['foo','bar','baz']);

CREATE INDEX ON bar USING gist(f);

ERROR:  data type text[] 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.

I'm trying to create an Exclusion Constraint on bar, so I need a GIST index.

0

2 Answers 2

2

smlar Extension

I was able to create a gist index on a text[] column using the smlar extension (written by Teodor Sigaev of text search fame)

# git clone git://sigaev.ru/smlar.git
# cd smlar/
# PATH=/usr/pgsql-9.6/bin:$PATH make USE_PGXS=1
# PATH=/usr/pgsql-9.6/bin:$PATH make USE_PGXS=1 install
# psql

postgres=# create extension smlar;
postgres=# create index on bar using gist(f _text_sml_ops);
1
  • 3
    Wonder why that's not in core then =( Commented Sep 8, 2017 at 0:07
1

Another option would be to create the index converting the column to ts_vector, this way you will not need to install smlar.

create index on bar using gist(array_to_tsvector(f));

When using the index, make sure you're using operations supported by tsvector, such as:

select * from bar where to_tsquery('search_value') @@ array_to_tsvector(f);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.