I write a postgresql and pass parameter name1
from my java code with Spring + Hibernate.
SELECT * FROM Test
WHERE name = COALESCE(:name1, name2)
but i got an error
ERROR: COALESCE types bytea and character varying
The type of name1
is String in my java code.
I tried to solve the problem
COALESCE(convert_from(:name1,'UTF8'), name2)
It will pass JUNIT Test in Eclipse. However when I run it on Tomcat, I will get an error
Error:convert_from(character varying, unknown) not exist
How to solve it? Thanks.
I have solve my question.
SELECT * FROM Test
WHERE name = COALESCE(CAST(:name1 AS TEXT), name2)
Thank Erwin Brandstetter for giving me advise.