Could not convert UTF-8 to ISO8859-1

From: Chris Anderson <cva(at)pobox(dot)com>
To: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Could not convert UTF-8 to ISO8859-1
Date: 2004-02-05 23:04:28
Message-ID: A6846A72-582F-11D8-84A2-000393D3B384@pobox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2004-02-06 03:39:41 Re: Slow sub-selects, max and count(*)
Previous Message Tom Lane 2004-02-05 16:54:15 Re: TIME ZONE SQL