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 E8EC1D1B199 for ; Thu, 15 Jul 2004 03:07:20 -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 07395-03 for ; Thu, 15 Jul 2004 06:07:19 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 0B04ED1B1B0 for ; Thu, 15 Jul 2004 03:07:11 -0300 (ADT) Received: from flood.opencloud.co.nz ([192.168.0.31] helo=opencloud.com ident=oliver) by yass.opencloud.co.nz with esmtp (Exim 3.35 #1 (Debian)) id 1BkzOi-0006Ag-00; Thu, 15 Jul 2004 18:07:12 +1200 Message-ID: <40F61F0E.6020907@opencloud.com> Date: Thu, 15 Jul 2004 18:07:10 +1200 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "Dario V. Fassi" Cc: "pgsql-jdbc@postgresql.org" Subject: Re: Very strange Error in Updates References: <40F6172D.10301@sistemat.com.ar> <40F619A0.8030506@opencloud.com> <40F61CC2.5030704@sistemat.com.ar> In-Reply-To: <40F61CC2.5030704@sistemat.com.ar> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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/173 X-Sequence-Number: 10557 Dario V. Fassi wrote: > > > Oliver Jowett wrote: > >> Dario V. Fassi wrote: >> >>> When the parameter fill the full-length of receiving field and has >>> any non common character, the update throw a exception like: >>> >>> java.sql.SQLException: ERROR: value too long for type character >>> varying(30) >>> at >>> org.postgresql.core.v2.QueryExecutorImpl.receiveErrorMessage(QueryExecutorImpl.java:420) >> >> >> >> >> >> What server version (I'm guessing <= 7.3 since the driver is using the >> V2 protocol) and database encoding are you using? >> >> -O > > > Server 7.3.4 for W2K and Linux too. > Encoding SQL_ASCII in both cases. You can only put 7-bit characters into a SQL_ASCII database. 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 1) the driver encodes the parameter as UNICODE (== UTF8); for characters above 127 this encoding will result in more than one byte per character. 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. 3) you end up with extra characters in the resulting value which exceeds the varchar's size. The solution is to use a database encoding that matches your data. -O