Nom*_*ron 1 postgresql json ruby-on-rails
我正在使用 Rails 4 作为 api 以 JSON 数据类型存储散列,并且需要在散列中搜索满足<&>条件的值。
例如,使用像 {location: {"lat": -112, "lng": 33}} 这样的散列,我需要能够找到一系列经纬度。
就像是:
Place.where("location ->> "lng" < -111 && > -113)
Run Code Online (Sandbox Code Playgroud)
Postgres 9.3 似乎并不支持这一点,但有没有办法在不使用以下内容的情况下解决这个问题:
Place.all.select { |place| place.location["lng"] < -111 && > -113 }
Run Code Online (Sandbox Code Playgroud)
我之前如何查询这个Place.where("location ->> 'lng' < ?", -111)有点不正确
出于某种原因,您必须按文本进行搜索(我相信有人可以在评论中回答为什么会这样),因此稍微更改查询以使其Place.where("location ->> 'lng' < ?", "-111")似乎有效!
| 归档时间: |
|
| 查看次数: |
1455 次 |
| 最近记录: |