繁体   English   中英

错误:运算符不存在:没有时区的时间戳 > 整数)

[英]ERROR: operator does not exist: timestamp without time zone > integer)

我正在使用 Rails 5.2 并传递一个日期参数。 为了简化我的例子,请看下面的 sql 查询,它很相似但被简化,因为它太复杂而无法与活动记录方法一起使用,所以我需要运行原始 sql..

sql = 'Select * FROM mytable WHERE created_at > #{@start_date_time}'

1) 如何在将参数传递到字符串或执行命令时对其进行清理。

2)我的日期应该是什么格式? 我试过 '2018-01-01 00:00:00.000' 和 '2018-01-01' 都出错了。

代码:

sql =count_query(@start_date_time, sender_type, sender_id)
records_array = ActiveRecord::Base.connection.execute(sql)

错误

ActiveRecord::StatementInvalid (PG::UndefinedFunction: 
ERROR:  operator does not exist: timestamp without time zone > integer)

LINE 11: WHERE created_at > 2018-01-01

WHERE created_at > '2018-01-01' 应该可以工作

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM