Fix logic for raw queries.