ActiveRecord: Support for PostgreSQL operator classes


I’d love to see support for PostgreSQL operator classes. An example use case is:

CREATE INDEX users_name ON users USING gist (name gist_trgm_ops);

USING is currently supported. However I cannot specify an operator class other than the default. In the example above the operator class is gist_trgm_ops, specified after the column name in the USING clause.

There was some discussion in the PR about the best syntax for this. Initially I chose:

add_index :users, [:name], using: :gist, opclasses: {name: :gist_trgm_ops}

After Sean’s suggestion I changed it to:

add_index :users, [:name], using: ‘gist (name gist_trgm_ops)’

The code is simpler in the latter case but I don’t know whether the syntax is right. One of the downsides is the ability to supply different columns in the second argument and in using: (as pointed out by Matthew).

My question is: what is the right syntax for this feature?

Best regards

Ooops, I forgot to include a link to the PR: