Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: COALESCE types bytea and character varying in PostgreSQL

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.

like image 205
LoveTW Avatar asked Dec 24 '13 03:12

LoveTW


1 Answers

I have solve my question.

SELECT * FROM Test
WHERE name = COALESCE(CAST(:name1 AS TEXT), name2)

Thank Erwin Brandstetter for giving me advise.

like image 107
LoveTW Avatar answered Sep 18 '22 20:09

LoveTW