pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@postnewspapers.com.au>
To: Kris Jurka <books@ejurka.com>
Cc: user2037@ymail.com
Cc: 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.
Date: Thu, 04 Jun 2009 08:34:00 +0800
Message-ID: <4A271678.6010405@postnewspapers.com.au> (raw)
In-Reply-To: <alpine.BSO.2.00.0906031639270.2432@leary.csoft.net>
References: <626803.19538.qm@web59808.mail.ac4.yahoo.com>
	<alpine.BSO.2.00.0906031639270.2432@leary.csoft.net>

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



view thread (6+ messages)  latest in thread

Message-ID: <4A271678.6010405@postnewspapers.com.au>
Permalink:  ../4A271678.6010405@postnewspapers.com.au/
Also on:    postgresql.org/message-id/4A271678.6010405@postnewspapers.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: craig@postnewspapers.com.au, books@ejurka.com, user2037@ymail.com
  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.
  In-Reply-To: <4A271678.6010405@postnewspapers.com.au>
  References: <626803.19538.qm@web59808.mail.ac4.yahoo.com> <alpine.BSO.2.00.0906031639270.2432@leary.csoft.net> <4A271678.6010405@postnewspapers.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox