【问题标题】:How to find all records from the db, where all values of the json field are greater than the current date?如何从 db 中查找所有记录,其中 json 字段的所有值都大于当前日期?
【发布时间】:2018-05-02 03:33:38
【问题描述】:
p = Post.last

p.change_dates = {'1': '2017-11-11', '2': '2017-10-11'}

change_dates 可以有多个键

我需要从数据库中查找所有记录,其中json字段的所有值都大于当前日期

我该怎么做?

【问题讨论】:

    标签: ruby-on-rails json ruby postgresql hash


    【解决方案1】:

    这应该可行:

    Post.where("change_dates->>'1' = ? or change_dates->>'2' = ?", Date.today, Date.today))
    

    【讨论】:

    • 是的,它会起作用的。但是我需要自动确定“1”和“2”,因为可以有更多这样的键,而不仅仅是“1”和“2”
    猜你喜欢
    • 1970-01-01
    • 2012-08-10
    • 2020-05-29
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    • 2022-01-12
    相关资源
    最近更新 更多