PostgreSQL conditional where clause
If anyone faced with the psql operator does not exist: bigint = bytea issue, here is my workaround:
WHERE ({client_id} < 0 AND sr.client_id > {client_id}) OR sr.client_id = {client_id}
Please consider that, client_id generally cannot be negative so you can use that information for eleminating the operation cast issue.
Check if its null OR your condition like this:
WHERE {client_id} IS NULL OR sr.client_id = {client_id}
The WHERE
clause evaluate as follow: If the variable is empty, then the WHERE
clause evaluate to true, and therefore - no filter. If not, it continue to the next condition of the OR