Skip to content
RED SAGSkills
hard20 pts · first answer countsindexingquery-tuning

Optional filters in one query

A search API uses the query below so that any filter can be skipped by passing NULL. With prepared statements, it is slow even when only city is given. Why?

SELECT * FROM shops
WHERE ($1::text IS NULL OR city = $1)
  AND ($2::text IS NULL OR category = $2)
  AND ($3::int  IS NULL OR rating >= $3);
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions