Fix sql - from_unixtime() for mysql and to_timestamp() for PostgreSQL

The current version is broken on Mysql.

This hasn't been tested on PostgreSQL but I can't see why it shouldn't work.