[英]Ordering Postgres jsonb in Rails
我正在嘗試使用rails中的jsonb列進行排序:
Stat.order("data ->'likes'->'followed_by' ASC")
我一直收到這個錯誤。
PG::UndefinedFunction: ERROR: could not identify an ordering operator for type json
我想不出是我的格式? followed_by屬性是一個int。
謝謝!
我不確定,但根據http://www.postgresql.org/docs/9.3/static/functions-json.html
->
“獲取JSON對象字段” ->>
“將JSON對象字段作為文本” 所以也許activerecord不能對field
進行排序,但可以對text
進行排序?
嘗試: Stat.order("data ->'likes'->>'followed_by' ASC")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.