I'm trying to order by a jsonb column in rails using:
Stat.order("data ->'likes'->'followed_by' ASC")
I keep getting this error returned.
PG::UndefinedFunction: ERROR: could not identify an ordering operator for type json
I can't figure out is it my formatting? The followed_by attribute is a int.
Thank you!
I'm not certain but according to http://www.postgresql.org/docs/9.3/static/functions-json.html
-> "Get JSON object field"->> "Get JSON object field as text"So perhaps activerecord can't sort the field but can sort the text?
Try: Stat.order("data ->'likes'->>'followed_by' ASC")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With