查找值与其他值不相交的条目

编程入门 行业动态 更新时间:2024-10-12 05:55:59
本文介绍了查找值与其他值不相交的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遇到了在Ruby on Rails中进行ActiveRecord查询的问题,它返回了所有用户 blocked_dates (自动生成的字符串值)不与 formatted_dates (自动生成的字符串值)。 我遇到的问题是,例如:

User.where.not(string_to_array ,',')&&&&&&&&&&&&&& b

返回一个空列表,其中:

User.where(string_to_array(blocked_dates,',')& ;& string_to_array(?,','),26.12.2015)

blocked_dates 实际包含26.12.2015的正确用户。

这个奇怪行为有理由吗?或者Postgres重叠运算符&&& 不能与 NOT 结合使用吗?

如果出现问题,这里是生成的SQL查询:

SELECTusers。 * FROMusersWHERE(NOT(string_to_array(blocked_dates,',')&& string_to_array('26 .12.2015',',')))

解决方案

好吧,我想我理解我的问题。 users表的blocked_dates的默认值为nil。因此,查询无法计算重叠。在我将blocked_dates的默认值改为而不是nil之后,NOT语句开始给我正确的值。

I am having issues making an ActiveRecord query in Ruby on Rails that gives me back all users, whose blocked_dates (autogenerated string value) do not intersect with the formatted_dates (autogenerated string value) of a given event. The problem I'm having is that, for example:

User.where.not("string_to_array(blocked_dates, ',') && string_to_array(?, ',')", "26.12.2015")

Gives back an empty list, whereby:

User.where("string_to_array(blocked_dates, ',') && string_to_array(?, ',')", "26.12.2015")

Gives back the correct users whose blocked_dates actually contain '26.12.2015'.

Is there a reason for this strange behavior? Or does the Postgres overlap operator && not work in conjunction with NOT?

In case the question arises, here is the generated SQL query:

SELECT "users".* FROM "users" WHERE (NOT (string_to_array(blocked_dates, ',') && string_to_array('26.12.2015', ',')))

解决方案

Ok, I think I understood the problem I had. The default value of "blocked_dates" of the users table was nil. Because of that, the query was not able to calculate overlaps. After I changed the default value of blocked_dates to "" instead of nil, the NOT statement started giving me the correct values.

更多推荐

查找值与其他值不相交的条目

本文发布于:2023-10-24 20:41:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524951.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条目   与其他

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!