添加带排序顺序的索引?

Shp*_*ord 6 migration postgresql indexing ruby-on-rails

在Rails中,如何在迁移到具有特定排序顺序的Postgres数据库时添加索引?

最终想要解决这个问题:

CREATE INDEX index_apps_kind_release_date_rating ON apps(kind, itunes_release_date DESC, rating_count DESC);
Run Code Online (Sandbox Code Playgroud)

但是现在我的迁移中有这个:

add_index :apps, [:kind, 'itunes_release_date desc', 'rating_count desc'], name: 'index_apps_kind_release_date_rating'
Run Code Online (Sandbox Code Playgroud)

哪个吐出这个:

CREATE INDEX "index_apps_kind_release_date_rating" ON "apps" ("kind", "itunes_release_date desc", "rating_count desc")
Run Code Online (Sandbox Code Playgroud)

出了哪些错误:

PG::Error: ERROR:  column "itunes_release_date desc" does not exist
Run Code Online (Sandbox Code Playgroud)

nit*_*gen 16

Rails现在支持在迁移中指定索引顺序:

def change
  add_index(:accounts, [:branch_id, :party_id, :surname], order: {branch_id: :desc, party_id: :asc})
end
Run Code Online (Sandbox Code Playgroud)

来自http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/add_index


Den*_*rdy 2

Rails 似乎不支持有序索引。

我怀疑您可以根据您之前的问题安全地删除 where 子句中的两个desc, btw: kindis ,因此 PG 应该很乐意以相反的顺序查找索引。