使用PostgreSQL的hstore查询方式?

时间:2016-05-18 02:40:19

标签: ruby-on-rails postgresql hstore

我在我的rails应用程序中使用PostgreSQL功能hstore,最近我添加了gin索引来加速我从hstore的查询。

add_index :articles, :published_at_translations, using: :gin

我调查了一些文章,例如提到的this

“@>”的速度至少快两倍(使用索引)

我的数据栏就像:

  

published_at_translations [   “EN”=> “中2016-05-17T10:36:06”, “CN”=> “中2016-05-17T10:36:06”]

旧查询:

scope :now_published, -> { where("published_at_translations -> ? <= ? and state_translations -> ? = ?", I18n.locale, DateTime.current, I18n.locale, :published ) }

新:

scope :now_published, -> { where("published_at_translations -> ? <= ? and state_translations @> '#{I18n.locale}=>#{:published}'", I18n.locale, DateTime.current ) }

但是我没有使用“@&gt;”添加&gt; =或&lt; = ...等条件,如何使用“@&gt;重构我的查询? “或以其他方式从杜松子酒指数获得加速效率?

0 个答案:

没有答案