0

I am developing a Rails application and using SQLite3 as my database server. I am having an issue querying conferences that have a to date_time that is less than Time.now. Here is the exact statement in my controller:

@conferences = @conferences.where("to < ?", Time.now)

Where @conferences is defined beforehand in my controller as

@conferences = @conferences.where("to < ?", Time.now)

I get the following error message:

SQLite3::SQLException: near "to": syntax error: SELECT "conferences".* FROM "conferences" WHERE "conferences"."country_id" = ? AND (to < '2019-08-16 22:45:57.891117') LIMIT ? OFFSET ?

I have tried setting up and reading more about LIMIT and OFFSET, but that didn't work probably because I don'thave a good understanding of what they do.

  • 1
    Possible duplicate of [SQLite DateTime comparison](https://stackoverflow.com/questions/1975737/sqlite-datetime-comparison) – computercarguy Aug 16 '19 at 23:05

1 Answers1

1

Change it to

@conferences = @conferences.where("\"to\" < ?", Time.now)

to is a reserved keyword in SQL. If you want to use it as a column name it has to be escaped with double quotes to mark it as an identifier instead.

Shawn
  • 47,241
  • 3
  • 26
  • 60