I'm using PL/pgSQL (PostgreSQL version 10) and wonder if there's a way to exclude statement from WHERE clause.
My code:
WHERE
(
e.priority >= priority_from AND
e.priority <= priority_to
) AND
v.id = vocabulary_id_ AND
e.text LIKE '%' || search_phrase || '%'
;
If the parameter vocabulary_id_ has value of 0 or null - the query returns 0 records because there's no such vocabulary with Id that equals 0 or null.
If I go with IF ELSE statement - I'll end up having 2 almost identical queries - one with v.id = vocabulary_id_ AND part, and the other without it.
Is there an easy way to exclude this part using PL/pgSQL syntax?
vocabulary_id_ is nullorvocabulary_id_=0?0is being passed.