Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL 9.X bytea representation in 'hex' or 'escape' for thumbnail images

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?

like image 635
AndreaBoc Avatar asked Oct 03 '22 19:10

AndreaBoc


1 Answers

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 for bytea output. Libpq's PQescapeByteaConn() 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.

like image 117
Erwin Brandstetter Avatar answered Oct 14 '22 14:10

Erwin Brandstetter