Re: Wrong length of bytea field

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Andrus Moor <eetasoft(at)online(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Wrong length of bytea field
Date: 2006-02-24 21:22:19
Message-ID: 20060224212219.GA88781@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Feb 24, 2006 at 10:32:58PM +0200, Andrus Moor wrote:
> It seems that for some reason postgres returns sometimes escaped string size
> (eq. single byte 0x00 uploaded as \\000 size is returned as 5 )

I'd guess that "some reason" is because the data was over-escaped
when it was inserted -- that is, escaped and then escaped again.
Try inserting a small file and querying for the bytea column and
see what you get.

CREATE TABLE foo (data bytea);

INSERT INTO foo VALUES ($$\000$$);
INSERT INTO foo VALUES ($$\\000$$);
INSERT INTO foo VALUES ($$\\\000$$);
INSERT INTO foo VALUES ($$\\\\000$$);

SELECT data, octet_length(data) FROM foo;
data | octet_length
---------+--------------
\000 | 1
\\000 | 4
\\\000 | 2
\\\\000 | 5
(4 rows)

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Josh Berkus 2006-02-24 21:52:51 Re: [GENERAL] Requesting LinuxWorld East staffers
Previous Message Bruce Momjian 2006-02-24 20:43:11 Re: [GENERAL] Requesting LinuxWorld East staffers