gpt4 book ai didi

ruby-on-rails - 如何在 hstore 列中的键上添加索引?

转载 作者:行者123 更新时间:2023-11-29 11:45:38 26 4
gpt4 key购买 nike

正在观看 http://railscasts.com/episodes/345-hstore

我决定实现一些 hstore 列。

据我了解

execute "CREATE INDEX products_gin_properties ON products USING GIN(properties)"

或更好地写成(Rails 4):

add_index :products, :properties, using: :gin

两者都只在 hstore 列上创建索引。

如何在 hstore 列中的键上添加索引?环顾四周,我可以做类似的事情:

execute "CREATE INDEX products_properties_name ON products (properties -> 'name')"

但是,是否有 Rails 4 方法来执行此操作?

最佳答案

只看这里的源代码:https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L418

    def add_index(table_name, column_name, options = {}) #:nodoc:
index_name, index_type, index_columns, index_options, index_algorithm, index_using = add_index_options(table_name, column_name, options)
execute "CREATE #{index_type} INDEX #{index_algorithm} #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} #{index_using} (#{index_columns})#{index_options}"
end

index_columns 是一个逗号分隔的列列表。

它似乎不受支持。

关于ruby-on-rails - 如何在 hstore 列中的键上添加索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19409239/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com