我遇到了在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.
更多推荐
查找值与其他值不相交的条目
发布评论