Fix generation of invalid SQL query.