We have one table: categories
|---------------------|------------------|
| category_id | name |
|---------------------|------------------|
| 1 | 'text 1' |
|---------------------|------------------|
| 2 | 'text 2' |
|---------------------|------------------|
We need to do this:
Pseudo SQL code:
SELECT * FROM categories WHERE case when $1 != 0 then category_id = $1 end;
$1 - input parameter's value
Is It possible to do it in PostgreSQL with one SQL query?
WHERE $1 =0 OR $1 = category_idWHERE $1 !=0 AND $1 = category_idin which case the comment above (by Nick) applies.CASEclause will return anullvalue when $1 = 0, and that's not a boolean value.