Re: The mysterious BLOB and bytea data types

From: "Hugh Mandeville" <hughmandeville(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: The mysterious BLOB and bytea data types
Date: 2001-08-16 22:12:05
Message-ID: 9lhgeh$25ig$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

i use bytea, it is easier than using the large object functions. you have
to escape your binary data on the way in (to work in the query string) and
unescape it on the way out.
> If you are using Perl DBD::Pg, it's done for you automatically.

i believe these are the escape rules for bytea (binary - string):
0 - \\000
\ - \\\\
non-printable characters - \ooo (where ooo is their 3 digit octet
value)
' - ''

and these i believe are the unescape rules for bytea (string - binary):
\ooo - N (where ooo is their 3 digit octet value)
\\ - \

test=# CREATE TABLE testbinary ( id serial PRIMARY KEY, data bytea);
test=# INSERT INTO testbinary (data) VALUES
('\\000\001\002Three''Four''\\\\Five');
INSERT 124403 1
test=# select octet_length(data), data FROM testbinary;
octet_length | data
--------------+-------------------------------
19 | \000\001\002Three'Four'\\Five
(1 row)

if you are not worried about space you could base64 encode the data and
store it as a varchar.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Gould 2001-08-16 22:28:47 Re: Killing inactive connections
Previous Message Tom Lane 2001-08-16 21:51:24 Re: Killing inactive connections