[英]ERROR: operator does not exist: timestamp without time zone > integer)
I am using Rails 5.2 and passing a date parameter.我正在使用 Rails 5.2 并传递一个日期参数。 To simplify my example, look at the below sql query, it is similar but simplified as it is too complex to be used with active record methods, so I need to run the raw sql..
为了简化我的例子,请看下面的 sql 查询,它很相似但被简化,因为它太复杂而无法与活动记录方法一起使用,所以我需要运行原始 sql..
sql = 'Select * FROM mytable WHERE created_at > #{@start_date_time}'
1) How do I sanitize the parameters as I pass them into a string or the execute command. 1) 如何在将参数传递到字符串或执行命令时对其进行清理。
2) What format should my date be in? 2)我的日期应该是什么格式? I tried '2018-01-01 00:00:00.000' and '2018-01-01' and both error.
我试过 '2018-01-01 00:00:00.000' 和 '2018-01-01' 都出错了。
CODE:代码:
sql =count_query(@start_date_time, sender_type, sender_id)
records_array = ActiveRecord::Base.connection.execute(sql)
ERROR错误
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.