查找值与其他值不相交的条目 [英] Find entry where value does not intersect with other value

查看:140
本文介绍了查找值与其他值不相交的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了在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.

这篇关于查找值与其他值不相交的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆