I am trying to create a GIN index through liquibase scripts.
CREATE INDEX IF NOT EXISTS index_name ON schema_name.table_name USING gin (column1, lower(column2) COLLATE pg_catalog."default" gin_trgm_ops)
Each time migration for the liquibae changeset fails with the following exception:
liquibase.exception.DatabaseException: ERROR: operator class "gin_trgm_ops" does not exist for access method "gin"
The problem is that this query works when run directly from pgAdmin query tool. There seems to be some issue when running this query from liquibase scripts.
I had to create the following extensions before creating the index from pgAdmin query tool. I am creating these extensions in the liquibase script too.
CREATE EXTENSION IF NOT EXISTS pg_trgm with schema public;
CREATE EXTENSION IF NOT EXISTS btree_gin with schema public;
Following is the part of my liquibase script that is creating the extensions and indexes. Btree index creating queries work well with the liquibase scripts. It fails with the above exception when trying to create GIN index.
CREATE EXTENSION IF NOT EXISTS pg_trgm with schema public;
CREATE EXTENSION IF NOT EXISTS btree_gin with schema public;
The following works:
CREATE INDEX IF NOT EXISTS index_name ON table_name USING btree (col1,col2 COLLATE pg_catalog."default")
CREATE INDEX IF NOT EXISTS index_name ON table_name USING btree (col1, col2 COLLATE pg_catalog."default")
But this fails:
CREATE INDEX IF NOT EXISTS index_name ON table_name USING gin (col1, lower(col2) COLLATE pg_catalog."default" gin_trgm_ops)