Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 8E90B1337B4E for ; Tue, 23 Nov 2010 10:22:30 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 96307-03 for ; Tue, 23 Nov 2010 14:22:23 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id C812C1337B5C for ; Tue, 23 Nov 2010 10:22:22 -0400 (AST) Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PKtlD-0001aT-KC for pgsql-jdbc@postgresql.org; Tue, 23 Nov 2010 15:22:19 +0100 Received: from 80.150.102.194 ([80.150.102.194]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 23 Nov 2010 15:22:19 +0100 Received: from spam_eater by 80.150.102.194 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 23 Nov 2010 15:22:19 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: getTables() doesn't handle umlauts correctly Date: Tue, 23 Nov 2010 15:22:10 +0100 Lines: 79 Message-ID: References: <4CEABC66.2010201@ttc-cmc.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 80.150.102.194 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 In-Reply-To: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.024 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_SORBS_WEB=0.77, RCVD_NUMERIC_HELO=1.164, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201011/73 X-Sequence-Number: 21194 Kris Jurka, 23.11.2010 09:13: > As the discussion has shown, trying to determine who is at fault here > is not trivial. The best way to show that postgresql (driver or > server if you're seeing it in pgadmin too) is at fault is to create a > test case creating the table and then querying the metadata. It would > be helpful to use either a Java or PG escape code for the special > character so it doesn't get mangled by either mail clients or build > environments. Then use String.codePointAt to print out the actual > data for both the table name used for construction and returned by > the metadata. That would conclusively show that PG is at fault > somewhere. OK, this is my test program: Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "postgres"); Statement stmt = con.createStatement(); stmt.executeUpdate("create table umlaut_ö (some_data varchar(10))"); stmt.executeUpdate("insert into umlaut_ö (some_data) values ('öäü')"); ResultSet rs = con.getMetaData().getTables(null, "public", "umlaut%", null); if (rs.next()) { String name = rs.getString("TABLE_NAME"); System.out.println("table name: " + name); System.out.print(" codepoints:"); for (int i = 0; i < name.length();) { int cp = name.codePointAt(i); System.out.print(" " + cp); i += Character.charCount(cp); } System.out.println(""); } rs.close(); rs = stmt.executeQuery("select count(*) from umlaut_ö where some_data = 'öäü'"); if (rs.next()) { int count = rs.getInt(1); System.out.println("number of rows: " + count); } rs.close(); rs = stmt.executeQuery("select some_data from umlaut_ö"); if (rs.next()) { String data = rs.getString(1); System.out.println("data: " + data); System.out.print(" codepoints:"); for (int i = 0; i < data.length();) { int cp = data.codePointAt(i); System.out.print(" " + cp); i += Character.charCount(cp); } System.out.println(""); } rs.close(); stmt.executeUpdate("drop table umlaut_ö"); stmt.close(); con.close(); The output on my computer is: table name: umlaut_test_� codepoints: 117 109 108 97 117 116 95 116 101 115 116 95 65533 number of rows: 1 data: öäü codepoints: 246 228 252 So it seems that the umlauts in the table name are returned with a different encoding than the data itself. Nevertheless the umlauts when being *sent* to the server are always treated correctly (as part of a table name as well as column values) This is with 9.0.1 on Windows XP using postgresql-9.0-801.jdbc4.jar Regards Thomas