use*_*677 5 postgresql activerecord ruby-on-rails-5.2
我正在使用 Rails 5.2 并传递一个日期参数。为了简化我的示例,请看下面的 sql 查询,它相似但经过简化,因为它太复杂而无法与活动记录方法一起使用,因此我需要运行原始 sql。
sql = 'Select * FROM mytable WHERE created_at > #{@start_date_time}'
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
错误
ActiveRecord::StatementInvalid (PG::UndefinedFunction:
ERROR: operator does not exist: timestamp without time zone > integer)
LINE 11: WHERE created_at > 2018-01-01
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26357 次 |
| 最近记录: |