Re: The mysterious BLOB and bytea data types - Mailing list pgsql-general

From Hugh Mandeville
Subject Re: The mysterious BLOB and bytea data types
Date
Msg-id 9lhgeh$25ig$1@news.tht.net
Whole thread Raw
In response to The mysterious BLOB and bytea data types  ("Dr. Evil" <drevil@sidereal.kz>)
List 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.




pgsql-general by date:

Previous
From: Einar Karttunen
Date:
Subject: Re: Re: Perfomance decreasing
Next
From: "mike"
Date:
Subject: GUI Application mode