[Haskell-cafe] bytea decoding

Bryan Green dbryan.green at gmail.com
Sun Jan 20 07:29:21 EST 2008

Does anyone know of a library that will handle bytea encodings from
postgres?  The bytea field that I need to access contains a jpg file.  I
want to retrieve it from the database and write it out for an image display


Bytea octets are also escaped in the output. In general, each
"non-printable" octet is converted into its equivalent three-digit octal
value and preceded by one backslash. Most "printable" octets are represented
by their standard representation in the client character set. The octet with
decimal value 92 (backslash) has a special alternative output
representation. Details are in Table

*Table 8-8. bytea Output Escaped Octets*
Decimal Octet ValueDescriptionEscaped Output Representation ExampleOutput
Result92backslash\\SELECT '\\134'::bytea;\\ 0 to 31 and 127 to 255
"non-printable" octets\*xxx* (octal value) SELECT '\\001'::bytea;\00132 to
126"printable" octetsclient character set representation SELECT

Depending on the front end to PostgreSQL you use, you may have additional
work to do in terms of escaping and unescaping bytea strings. For example,
you may also have to escape line feeds and carriage returns if your
interface automatically translates these.

So, here is part of the file from the database:


I may have to write a converter myself but I don't like re-inventing the
wheel if I don't need to do so.  Any pointers would be greatly appreciated.

Bryan Green
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080120/dd8135a8/attachment.htm

More information about the Haskell-Cafe mailing list