Actually, it works as it should:
Here
AND upper(rr.rel_type) = coalesce('CUSTOMER1','PRIMDEBTOR','CUSTOMER2')
the result of COALESCE
is 'CUSTOMER1'
- first not null value, and here
17918854 Customer2
17149146 Customer2
you have only 'CUSTOMER2'
.
So it's correct:
AND upper(rr.rel_type) = coalesce('CUSTOMER1','PRIMDEBTOR','CUSTOMER2')
=>
AND 'CUSTOMER2' = 'CUSTOMER1'
is false.