From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andy Shellam <andy-lists@networkmail.eu>
Cc: pgsql-sql@postgresql.org
Subject: Re: Storing null bytes in bytea
Date: Mon, 27 Apr 2009 16:29:09 -0400
Message-ID: <11364.1240864149@sss.pgh.pa.us> (raw)
In-Reply-To: <49F5F02A.1070505@networkmail.eu>
References: <49F5F02A.1070505@networkmail.eu>
Andy Shellam <andy-lists@networkmail.eu> writes:
> Because of the nul bytes, I've set the session_data column to be a bytea
> column in my database table. However I cannot get PostgreSQL to read
> past the first nul byte on an insert, so the unserialize call fails when
> it reads it back out the database and the remaining data is omitted.
Your example works fine in psql:
regression=# create table t1 (f1 bytea);
CREATE TABLE
regression=# insert into t1 values (E'IsLoggedIn|b:1;CurrentUser|O:17:"Class_SystemUser":4:{s:26:"\\000Class_SystemUser}'::bytea);
INSERT 0 1
regression=# select * from t1;
f1
-----------------------------------------------------------------------------------
IsLoggedIn|b:1;CurrentUser|O:17:"Class_SystemUser":4:{s:26:"\000Class_SystemUser}
(1 row)
I suspect what is happening is that some layer on the client side is
doubling (or perhaps undoubling?) the backslashes for you. Exactly
what are you doing with that literal as you build the query? It might
help to turn on log_statements so that you can see just what the
server is getting.
regards, tom lane
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, andy-lists@networkmail.eu
Subject: Re: Storing null bytes in bytea
In-Reply-To: <11364.1240864149@sss.pgh.pa.us>
* 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