Modify some queries to avoid them fails with postgresql