enjaku enjaku - 2 months ago 9
MySQL Question

rewrite postgresql query to use with mysql

I have a postgresql query in my Ruby on Rails application, which I have to rewrite to use it with mysql. And I don't understand how to do it, I always have an error and I think it is something concerning timestamps.
Here is the query:

includes(:mass_scan_list)
.where("mass_scan_lists.enabled = ?", true)
.order("mass_scan_lists.urgent DESC,
CASE mass_scan_lists.urgent WHEN true THEN extract(epoch from mass_scan_tasks.updated_at) ELSE -extract(epoch from mass_scan_tasks.updated_at) END")

Answer

Replace extract(epoch from mass_scan_tasks.updated_at) with unix_timestamp(mass_scan_tasks.updated_at)