fix time comparison in postgres