gpt4 book ai didi

postgresql - 错误 : operator does not exist: timestamp without time zone > integer)

转载 作者:行者123 更新时间:2023-12-05 04:00:39 24 4
gpt4 key购买 nike

我正在使用 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' 应该有效

关于postgresql - 错误 : operator does not exist: timestamp without time zone > integer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56032007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com