I tried to run this query in PostgreSQL 10:
select e.errordescription,
CASE
WHEN e.reworkempid is not null THEN get_empname(e.reworkempid)
else null
end
from error_log_gs e
where e.qcworkpackageid=3012175 and e.logno=1
Got the error:
set-returning functions are not allowed in CASE
Use a lateral join
instead:
select e.errordescription, ge.name
from error_log_gs e left join lateral
get_empname(e.reworkempid) ge(name)
on e.reworkempid is not null
where e.qcworkpackageid = 3012175 and e.logno = 1 ;