X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3FAC8DA054 for ; Tue, 4 Oct 2005 17:37:14 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 74107-06 for ; Tue, 4 Oct 2005 20:37:11 +0000 (GMT) Received: from gwmta.wicourts.gov (gwmta.wicourts.gov [165.219.244.91]) by svr1.postgresql.org (Postfix) with ESMTP id 3B9B6D9FE2 for ; Tue, 4 Oct 2005 17:37:11 -0300 (ADT) Received: from Courts-MTA by gwmta.wicourts.gov with Novell_GroupWise; Tue, 04 Oct 2005 15:37:14 -0500 Message-Id: X-Mailer: Novell GroupWise Internet Agent 6.5.4 Date: Tue, 04 Oct 2005 15:37:07 -0500 From: "Kevin Grittner" To: , Cc: Subject: Re: Selecting on non ASCII varchars Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.003 required=5 tests=[AWL=0.003] X-Spam-Level: X-Archive-Number: 200510/15 X-Sequence-Number: 13946 A String object doesn't contain an array of bytes; it contains an array of characters. Somehow you created String objects from bytes using the wrong character encoding technique (not to be confused with a character set). Your str.getBytes() is using the default encoding scheme to convert the characters to bytes. In this case, it seems that all the characters are mapping back to the original bytes, although I don't think that's always necessarily going to happen. By specifying the "utf-8" in the String constructor, you're telling it to use a specific encoding technique to convert those bytes to characters. =20 There is nothing in a String object to "flag" it for any particular encoding. The encoding only comes into play when turning bytes into characters or vice versa. =20 -Kevin =20 =20 >>> Jeremy LaCivita 10/04/05 3:16 PM >>> Hmmm so it turns out if i take all my Strings and do this: str =3D new String(str.getBytes(), "utf-8"); then it works. Correct me if i'm wrong, but that says to me that the Strings were in =20 UTF-8 already, but Java didn't know it, so it couldn't send them to =20 postgres properly. because str.getBytes() will return the same bytes that were used to =20 create the string, and new String(bytes, "utf-8") will repackage them =20 into a string using utf-8, so nothing has really changed at the byte =20 level, java has just explicitly marked it as UTF-8. Anyway, problem solved. As to why my strings aren't flagged as =20 UTF-8, thats not a postgres problem. Thanks! -jl On Oct 2, 2005, at 9:41 PM, Oliver Jowett wrote: > Jeremy LaCivita wrote: > > >> PreparedStatement pst =3D conn.prepareStatement("SELECT * from =20 >> mytable m >> where m.title ~* ?"); >> > > If you use direct equality (=3D), does it work? > > There have been comments on pgsql-bugs recently that some areas of the > backend code (case insensitive comparison and regexp) do not work > correctly in all cases when multibyte encodings are used. You might =20 > want > to repost to -bugs if basic equality works correctly. > > Do you have a selfcontained testcase we can try? In particular we need > to know the actual column values and regexp patterns you have =20 > problems with. > > -O >