我想獲取本地數據庫上的記錄。Rails | SQL在哪裏日期時間和日期
我的列從&到dateranges,我想將日期範圍轉換爲日期以查找記錄。 date = Date.parse(2017-02-17)
sc = schedules.where("from <= ? AND to >= ?",date,date)
給出錯誤;
SELECT "schedule_days".* FROM "schedule_days" WHERE "schedule_days"."car_id" = ? AND (from <= '2017-02-17' AND to >= '2017-02-17') [["car_id", 2]] SQLite3::SQLException: near "from": syntax error: SELECT "schedule_days".* FROM "schedule_days" WHERE "schedule_days"."car_id" = ? AND (from <= '2017-02-17' AND to >= '2017-02-17') ActiveRecord::StatementInvalid: SQLite3::SQLException: near "from": syntax error: SELECT "schedule_days".* FROM "schedule_days" WHERE "schedule_days"."car_id" = ? AND (from <= '2017-02-17' AND to >= '2017-02-17')
這是問題,因爲從&到有日期時間?我也試過了;
schedules.where("date(from) <= ? AND date(to) >= ?",date,date)
沒有運氣。然後,我會將此代碼推送到heroku postgresql
更改列名解決了問題http://stackoverflow.com/questions/1992019/how-can-i-rename-a-database-column-in-a-ruby-on-rails-migration –