Thread: Could not convert UTF-8 to ISO8859-1

Could not convert UTF-8 to ISO8859-1

From
Chris Anderson
Date:
I've noticed a difference in behavior between 7.2 and 7.3 with regards 
to character recoding and I'm a little perplexed about how to work 
around.

I have a database in LATIN-1 that is accessed read-write by a Java app. 
Naturally, the Java code keeps all of its strings in UTF8 so when I 
prepare a sql statement, someone is recoding these characters to 
LATIN-1 for me.

In 7.2, if the Unicode string contained a character that wasn't valid 
in the database encoding (LATIN-1) either pgsql or the jdbc driver (I'm 
not really sure which) would silently convert these characters to 
question marks.

In 7.3, the same string will throw a "Could not convert UTF-8 to 
ISO8859-1" error.

I can work around this by doing the following hack in Java:
String s = "some unicode string";byte[] tmp = s.getBytes("latin1");s = new String(tmp, 0, tmp.length, "latin1");

But I'm sure there is a better way to do this.

Any suggestions?

cva