Reputation: 1695
I have a column in one of my model's (team_opps) that is a datetime column called start_date. I recently migrated my db from sqlite3 to postgresql and this blew up the method.
Here is the method that was working in sqlite3:
def self.monday_team_opps
where('strftime("%w", "start_date") = "?"', 1)
end
The error that it gives is:
PG::UndefinedColumn: ERROR: column "%w" does not exist
Meaning it doesn't like the strftime. Can anyone clarify what needs to be adjusted to make this work in pgsql?
Thanks!
Upvotes: 0
Views: 419
Reputation: 17939
def self.monday_team_opps
where("extract(day from start_date) = ?", 1)
end
Upvotes: 0
Reputation: 29359
Try this
def self.monday_team_opps
where('EXTRACT(DOW FROM start_date) = ?', 1)
end
Upvotes: 4