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.

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Kris Jurka <books(at)ejurka(dot)com>
Cc: user2037(at)ymail(dot)com, pgsql-jdbc(at)postgresql(dot)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.
Date: 2009-06-04 00:34:00
Message-ID: 4A271678.6010405@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Kris Jurka wrote:
>
>
> On Wed, 3 Jun 2009, user2037(at)ymail(dot)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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Vaibhav Patil 2009-06-04 04:58:02 COPY FROM STDIN support for JDK 1.6
Previous Message Craig Ringer 2009-06-04 00:28:18 Re: jdbc excpetions in pg