Make query Postgres compatible