gpt4 book ai didi

ruby-on-rails - 返回没有特定键的记录 - Rails4 HStore Postgresql 查询

转载 作者:行者123 更新时间:2023-12-04 07:34:53 25 4
gpt4 key购买 nike

我有一个模型任务

t.string   "name"
t.hstore "actions"

例子:

#<Task id: 1, name: "first", actions: {"today"=>"9"}, 
#<Task id: 2, name: "second", actions: {"yesterday"=>"1"},
#<Task id: 3, name: "third", actions: nil,
#<Task id: 4, name: "four", actions: {"today"=>"11"},

我需要找到所有记录,其中 actions: nil, :today<10 和 key :today 不存在。这是1,2,3任务。

Task.where("actions -> 'today' < '10'") - it return only first task.
Task.where("actions -> 'today' < '10' OR actions IS NULL") - it return 1 and 3 records.

我如何找到所有没有关键字 :today in action 的记录?

最佳答案

来自 here ,根据你的问题:

Task.where("actions IS NULL OR EXIST(actions, 'today') = FALSE")

根据您的意见:

Task.where("actions -> 'today' < '10' OR actions IS NULL OR EXIST(actions, 'today') = FALSE")

关于ruby-on-rails - 返回没有特定键的记录 - Rails4 HStore Postgresql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17645329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com