Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 37C35633B67 for ; Mon, 27 Apr 2009 16:15:21 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 97920-08 for ; Mon, 27 Apr 2009 16:15:19 -0300 (ADT) X-Greylist: delayed 01:24:24.644804 by SQLgrey-1.7.6 Received: from smtp-gw51.mailanyone.net (smtp-gw51.mailanyone.net [208.70.128.77]) by mail.postgresql.org (Postfix) with ESMTP id A4D1B633AF4 for ; Mon, 27 Apr 2009 16:15:18 -0300 (ADT) Received: from mailanyone.net by smtp-gw51.mailanyone.net with esmtpa (MailAnyone extSMTP andy@networkmail.eu) id 1LyUxP-0002q5-5P for pgsql-sql@postgresql.org; Mon, 27 Apr 2009 12:49:31 -0500 Message-ID: <49F5F02A.1070505@networkmail.eu> Date: Mon, 27 Apr 2009 18:49:30 +0100 From: Andy Shellam User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Storing null bytes in bytea Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/129 X-Sequence-Number: 32475 Hi all, I was going to post this on the pgsql-php list but I think the issue is more on the PostgreSQL side of things. I'm using PHP 5.2.9 connected to a PostgreSQL 8.3.7 server running on Solaris 10 to try to store the session data for an application using a custom session handler class. The session data (objects/class instances etc) is serialized into raw bytes in PHP and contains a few nul/zero bytes (which are meaningful to PHP when it comes to deserializing the data.) 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. An example of such query is this: INSERT INTO system.session (user_id, session_key, session_name, client_browser, date_created, date_expires, ip_address, session_data) VALUES (NULL, '4pc4sjciahoc4fuk1bt4kohe91'::character varying(32), 'AppName'::character varying(50), 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.0.9) Gecko/2009040821 Firefox/3.0.9 (.NET CLR 3.5.30729)'::character varying(200), public.get_pg_timestamp(1240853862::integer), public.get_pg_timestamp(1240854162::integer), '192.168.0.8'::inet, E'IsLoggedIn|b:1;CurrentUser|O:17:"Class_SystemUser":4:{s:26:"\\000Class_SystemUser}'::bytea); All other columns are fine, but when it comes to the session_data column, all I end up with is 'IsLoggedIn|b:1;CurrentUser|O:17:"Class_SystemUser":4:{s:26:"'. Everything past the first "\\0000" byte sequence is ignored. I've tried this with and without the 'E' at the beginning of the value string. Any pointers as to what I'm doing wrong? Thanks, Andy