I have a query, in which some parameters can sometimes arrive null, and when these arrive null, I want them to ignore those conditions.
SELECT DISTINCT on (i.empleado) i.id
FROM rrhh.imputacion as i
INNER JOIN rrhh.empleado as e ON e.id = i.empleado
JOIN commons.persona AS pe ON e.persona_comun = pe.id
INNER JOIN rrhh.parte__imputaciones as pi ON pi.imputacion = i.id
INNER JOIN rrhh.parte as p ON pi.parte = p.id
WHERE i.dia >= '2017-12-04' AND i.dia <= '2017-12-11' and p.borrador = false AND e.fecha_fin_contrato IS NULL AND e.security_domain_id = 2
and i.empleado = 126
ORDER BY i.empleado, i.dia DESC,i.id
I need if the value of my parameter:
"and i.empleado = 126" <- if the value is NULL, ignore this, and bring all the records, without filtering by i.empleado
I do not see concrete examples for postgres.
Thank you.