简体   繁体   English

运算符不存在:没有时区的时间戳~~ *未知的Ruby代码

[英]operator does not exist: timestamp without time zone ~~* unknown ruby code

I am try to query users in the database when I do a search. 搜索时,我尝试查询数据库中的用户。 However i am getting a specific error which is 'operator does not exist: timestamp without time zone ~~* unknown' 但是我遇到一个特定的错误,即“操作员不存在:没有时区的时间戳~~ *未知”

In my database, the record of data_of_birth is saving in the format below. 在我的数据库中,data_of_birth的记录以以下格式保存。 Now sure what I am missing. 现在确定我所缺少的。 Code below 下面的代码

field == "dob"
            selected_date = Date.strptime(query, '%Y-%m-%d')
            items = Patient.joins(role: :user).where('users.date_of_birth ILIKE :search', search: "%#{selected_date}%")

Here how date_of birth is saving in the DB 这里date_of birth是如何保存在数据库中的

 date_of_birth: "1997-03-29 00:00:00"

Timestamps are stored as numbers in the database, not as strings, so using string comparisons (eg ILIKE ) won't work. 时间戳记以数字形式存储在数据库中,而不是以字符串形式存储,因此使用字符串比较(例如ILIKE )将不起作用。

It sounds like you're trying to match timestamps to dates. 听起来您正在尝试将时间戳与日期进行匹配。 You can simply cast the timestamp to a date for that. 您可以简单地将时间戳转换为该日期。 Something like: 就像是:

WHERE users.date_of_birth::date = '2019-06-14'

That would seem to translate to the following, based on your code. 根据您的代码,这似乎可以转换为以下内容。

field == "dob"
        selected_date = Date.strptime(query, '%Y-%m-%d')
        items = Patient.joins(role: :user).where('users.date_of_birth::date = :search', search: "%#{selected_date}%")

I'm unfamiliar with the libraries you're using, but it looks like the "::date" part might run into the placeholder functionality. 我不熟悉您使用的库,但看起来“ :: date”部分可能会遇到占位符功能。 You may need to tinker with that in order for it to work. 您可能需要对此进行修补才能起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL: 函数 trunc(timestamp without time zone, "unknown") 不存在 - SQL: function trunc(timestamp without time zone, "unknown") does not exist PostgreSQL:运算符不存在:没有时区的时间戳==没有时区的时间戳 - PostgreSQL: operator does not exist: timestamp without time zone == timestamp without time zone 获取错误函数to_date(没有时区的时间戳,未知)不存在 - Getting error function to_date(timestamp without time zone, unknown) does not exist SQL 执行失败:运算符不存在:bigint >= timestamp without time zone - SQL execution failed: operator does not exist: bigint >= timestamp without time zone 出现错误“功能周(没有时区的时间戳)不存在” - Getting error “function week(timestamp without time zone) does not exist” 错误:函数 date_trunc(timestamp without time zone) 不存在 - ERROR: function date_trunc(timestamp without time zone) does not exist PostgresException:42883:尝试调用过程时,函数X(没有时区的时间戳)不存在 - PostgresException: 42883: function X(timestamp without time zone) does not exist when trying to call procedure 如何将没有时区的时间转换为没有时区的时间戳? - How to convert time without time zone to timestamp without time zone? 运算符不存在:文本 ->> 未知 - operator does not exist: text ->> unknown Postgresql ERROR:运算符不存在:date ~~ unknown - Postgresql ERROR: operator does not exist: date ~~ unknown
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM