I'm using the Sequel library in Ruby by Jeremy Evans and I'm trying to order by a field in json.
I can get this to work in SQL with this Postgres query:
SELECT * FROM files ORDER BY json->>'filename' ASC
but i can't get this to work with Sequel/Postgres
table.order("json ->'filename'")
This results in the following SQL:
SELECT * FROM "files" ORDER BY 'json ->''filename'''
giving the error:
PG::SyntaxError: ERROR: non-integer constant in ORDER BY
LINE 1: ... ORDER BY 'json ->''...
Problem solved:
table.order(Sequel.lit("json ->'filename'"))