Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 3CA28634949 for ; Wed, 3 Jun 2009 21:34:06 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 11581-03 for ; Wed, 3 Jun 2009 21:34:04 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.61.230.242]) by mail.postgresql.org (Postfix) with ESMTP id 17081634946 for ; Wed, 3 Jun 2009 21:34:05 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id A64655C1BA; Thu, 4 Jun 2009 08:34:01 +0800 (WST) Received: from [10.0.0.53] (wallace.localnet [10.0.0.53]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 92EC01E0436; Thu, 4 Jun 2009 08:34:01 +0800 (WST) Message-ID: <4A271678.6010405@postnewspapers.com.au> Date: Thu, 04 Jun 2009 08:34:00 +0800 From: Craig Ringer User-Agent: Thunderbird 2.0.0.21 (X11/20090409) MIME-Version: 1.0 To: Kris Jurka CC: user2037@ymail.com, pgsql-jdbc@postgresql.org Subject: Re: Strings with null characters produce exceptions when selected or inserted. Attempts to select messages with null bytes produces "ERROR: insufficient data left in message". And inserting produces "ERROR: invalid byte sequence for encoding \"UTF8\": 0x00". Since a null character is a valid UTF code point why is it rejected by the JDBC driver? The attached test can work with Mysql and their JDBC driver. References: <626803.19538.qm@web59808.mail.ac4.yahoo.com> In-Reply-To: X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200906/21 X-Sequence-Number: 19685 Kris Jurka wrote: > > > On Wed, 3 Jun 2009, user2037@ymail.com wrote: > >> Strings with null characters produce exceptions when selected or >> inserted. Attempts to select messages with null bytes produces "ERROR: >> insufficient data left in message". And inserting produces "ERROR: >> invalid byte sequence for encoding \"UTF8\": 0x00". >> >> Since a null character is a valid UTF code point why is it rejected by >> the JDBC driver? > > Because the server can't handle it. The server is written in C and > tracks all textual data as C strings which are null terminated. It > cannot handle intermediate null bytes, so the driver is just providing > that message as early as possible to you. Note that the `bytea' type _does_ store null bytes fine. It's interesting that \0x00 is in fact valid utf-8, since it raises the question of whether Pg should in fact support null bytes in `text' and `varchar' strings. -- Craig Ringer