Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 3B7916339FF for ; Mon, 27 Apr 2009 17:29:15 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 98228-05 for ; Mon, 27 Apr 2009 17:29:08 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id D8CA26335AD for ; Mon, 27 Apr 2009 17:29:12 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n3RKT9gU011365; Mon, 27 Apr 2009 16:29:09 -0400 (EDT) To: Andy Shellam cc: pgsql-sql@postgresql.org Subject: Re: Storing null bytes in bytea In-reply-to: <49F5F02A.1070505@networkmail.eu> References: <49F5F02A.1070505@networkmail.eu> Comments: In-reply-to Andy Shellam message dated "Mon, 27 Apr 2009 18:49:30 +0100" Date: Mon, 27 Apr 2009 16:29:09 -0400 Message-ID: <11364.1240864149@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.162 tagged_above=0 required=5 tests=AWL=0.162 X-Spam-Level: X-Archive-Number: 200904/131 X-Sequence-Number: 32477 Andy Shellam 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