Postgresql 如何在rails 5中添加带lower函数的三元索引

Postgresql 如何在rails 5中添加带lower函数的三元索引,postgresql,ruby-on-rails-5,Postgresql,Ruby On Rails 5,要使用三元索引,我需要这样写 add_index :people, :last_name, using: :gist, opclass: { last_name: :gist_trgm_ops } 我想使用它的LOWER功能 add_index :people, "lower(last_name)", using: :gist, opclass: { "lower(last_name)" => :gist_trgm_ops } 我可以运行此迁移,但似乎索引创建不正确。 使用execut

要使用三元索引,我需要这样写

add_index :people, :last_name, using: :gist, opclass: { last_name: :gist_trgm_ops }
我想使用它的
LOWER
功能

add_index :people, "lower(last_name)", using: :gist, opclass: { "lower(last_name)" => :gist_trgm_ops }
我可以运行此迁移,但似乎索引创建不正确。 使用
execute
命令,我可以创建适当的索引

execute "CREATE INDEX index_people_on_lower_last_name ON people USING GIST (lower(last_name) gist_trgm_ops);"

尽可能避免使用
execute
。是否有更好的方法使用postgres函数为trigram索引编写迁移文件?

为什么要这样做?trigram索引支持的所有操作都有不区分大小写的变体。就用吧。谢谢,我认为这是区分大小写的。你可以选择。LIKE区分大小写,ILIKE不区分大小写<代码>~区分大小写,
~*
不区分大小写。
没有区分大小写的变体,因此您并不总是有选择,但如果您没有选择,它就是在您想要的方向上。