X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id EA154D1B1CE for ; Thu, 15 Jul 2004 11:16:13 -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 87020-03 for ; Thu, 15 Jul 2004 14:16:22 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 93319D1B1AA for ; Thu, 15 Jul 2004 11:16:11 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i6FEGHYP020560; Thu, 15 Jul 2004 10:16:18 -0400 (EDT) To: Oliver Jowett Cc: "Dario V. Fassi" , "pgsql-jdbc@postgresql.org" Subject: Re: Very strange Error in Updates In-reply-to: <40F61F0E.6020907@opencloud.com> References: <40F6172D.10301@sistemat.com.ar> <40F619A0.8030506@opencloud.com> <40F61CC2.5030704@sistemat.com.ar> <40F61F0E.6020907@opencloud.com> Comments: In-reply-to Oliver Jowett message dated "Thu, 15 Jul 2004 18:07:10 +1200" Date: Thu, 15 Jul 2004 10:16:17 -0400 Message-ID: <20559.1089900977@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/187 X-Sequence-Number: 10571 Oliver Jowett writes: > The JDBC driver always speaks UNICODE when it can, since that matches > Java's internal string representation. I suspect that what's happening is: > 0) the driver sets client_encoding = UNICODE during connection setup Right. > 1) the driver encodes the parameter as UNICODE (== UTF8); for characters > above 127 this encoding will result in more than one byte per character. Right. > 2) the server converts from client_encoding UNICODE to database encoding > SQL_ASCII; for characters that are invalid in SQL_ASCII (>127) it does > some arbitary conversion, probably just copying the illegal values > unchanged. Not really. SQL_ASCII encoding basically means "we don't know what this data is, just store it verbatim". So the UTF-8 string sent by the driver is stored verbatim. > 3) you end up with extra characters in the resulting value which exceeds > the varchar's size. Right. Since the server does not know what encoding is in use, it falls back to the assumption that 1 character == 1 byte, under which assumption the string violates the varchar(30) constraint. Had the server known which encoding was in use, it would have counted the characters correctly. > The solution is to use a database encoding that matches your data. Actually, if you intend to access the database primarily through JDBC, it'd be best to use server encoding UNICODE. The JDBC driver will always want UNICODE on the wire, and I see no reason to force extra character set conversions. Non-UNICODE-aware clients can be handled by setting client_encoding properly. regards, tom lane