Add cast only when datatype differ in postgres where clause