【问题标题】:Ordering by json field in ruby Sequel/Postgres按 ruby​​ Sequel/Postgres 中的 json 字段排序
【发布时间】:2018-08-18 00:24:15
【问题描述】:

我正在使用 Jeremy Evans 编写的 Ruby 中的 Sequel 库,我正在尝试按 json 中的字段排序。

我可以通过这个 Postgres 查询让它在 SQL 中工作:

SELECT * FROM files ORDER BY json->>'filename' ASC

但我无法让它与 Sequel/Postgres 一起使用

table.order("json ->'filename'")

这会产生以下 SQL:

SELECT * FROM "files" ORDER BY 'json ->''filename'''

给出错误:

PG::SyntaxError: ERROR: non-integer constant in ORDER BY LINE 1: ... ORDER BY 'json ->''...

【问题讨论】:

    标签: json ruby postgresql sequel


    【解决方案1】:

    问题解决了:

    table.order(Sequel.lit("json ->'filename'"))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-21
      • 1970-01-01
      • 1970-01-01
      • 2013-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-19
      相关资源
      最近更新 更多