fixed query syntax for postgres