【问题标题】:ruby sequel access json fieldruby 续集访问 json 字段
【发布时间】:2015-06-06 08:51:38
【问题描述】:

我有以下架构:

 Column  |            Type             |       Modifiers        
---------+-----------------------------+------------------------
 id      | text                        | not null
 data    | json                        | not null
 created | timestamp without time zone | not null default now()

如果我打开 psql,我可以运行查询。

select id, data->'amount' as amount from plans;

但是 ruby​​ sequel gem 毁了它。

puts $db.run("select id, data->'amount' as amount from plans")

怎么了?

【问题讨论】:

    标签: ruby json postgresql sequel


    【解决方案1】:

    需要#literal 方法。

    $db.run("select id, data -> #{ $db.literal('amount') } as amount from plans")
    

    【讨论】:

      猜你喜欢
      • 2018-10-31
      • 1970-01-01
      • 2017-11-30
      • 2013-11-25
      • 2012-05-25
      • 2021-03-04
      • 2020-09-29
      • 2016-11-09
      • 1970-01-01
      相关资源
      最近更新 更多