2013-10-16 41 views
3

看着http://railscasts.com/episodes/345-hstore如何在hstore列中的某個鍵上添加索引?

我決定實施一些hstore列。

從我的理解

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

或更好的寫法如下(軌道4):

add_index :products, :properties, using: :gin 

都只有建立在hstore列的索引。

我該如何在hstore列中的某個鍵上添加索引?看看周圍,我可以做類似的東西:

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

但是,有沒有一個Rails 4方法來做到這一點?

回答

3

只是看着這裏的源代碼: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是用逗號分隔的列清單。

它似乎並不支持。

相關問題