Fix bug with constants in queries