Changes queries so that they work in postgresql