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 program.
bytea:
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 8-8.
Table 8-8. bytea Output Escaped Octets
Decimal Octet Value | Description | Escaped Output Representation | Example | Output Result |
---|---|---|---|---|
92 | backslash | \\ | SELECT '\\134'::bytea; | \\ |
0 to 31 and 127 to 255 | "non-printable" octets | \xxx (octal value) | SELECT '\\001'::bytea; | \001 |
32 to 126 | "printable" octets | client character set representation | SELECT '\\176'::bytea; | ~ |
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.