Re: Storing null bytes in bytea

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andy Shellam <andy-lists(at)networkmail(dot)eu>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Storing null bytes in bytea
Date: 2009-04-27 20:29:09
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

Andy Shellam <andy-lists(at)networkmail(dot)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);
regression=# insert into t1 values (E'IsLoggedIn|b:1;CurrentUser|O:17:"Class_SystemUser":4:{s:26:"\\000Class_SystemUser}'::bytea);
regression=# select * from t1;
(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

In response to


Browse pgsql-sql by date

  From Date Subject
Next Message Emi Lu 2009-04-28 15:43:09 pg_stat_activity return all connections
Previous Message Leif B. Kristensen 2009-04-27 19:37:47 Re: Multiple return values and assignment