fix queries so they are constructed based on the postgres version