another fix of malformed postgresql queries