问题
My application (developed in Delphi and ZEOS components) uses PostgreSQL 8.4 and stores some thumbnail images into a bytea
column.
I want to migrate to PostgreSQL 9.2 and have restored the dump and everything works fine except when I try to retrieve those images: Postgres 9.2 uses hex
for output representation instead of escape
used in Postgres 8.4.
There are two possible solutions: Change the Postgres 9.2 settings for escape
representation or change the hex
string in binary data via application. But what is the best solution? Why did PostgreSQL 9.X change to hex
for bytea
representation?
It is a simple setup or are there technical reasons?
回答1:
A rationale was given in the release notes of Postgres 9.0:
- Allow
bytea
values to be written in hex notation (Peter Eisentraut)The server parameter
bytea_output
controls whether hex or traditional format is used forbytea
output. Libpq'sPQescapeByteaConn()
function automatically uses the hex format when connected to PostgreSQL 9.0 or newer servers. However, pre-9.0 libpq versions will not correctly process hex format from newer servers.The new hex format will be directly compatible with more applications that use binary data, allowing them to store and retrieve it without extra conversion. It is also significantly faster to read and write than the traditional format.
You already seem to be aware of bytea_output.
来源:https://stackoverflow.com/questions/17157816/postgresql-9-x-bytea-representation-in-hex-or-escape-for-thumbnail-images