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

怎甘沉沦 提交于 2020-01-03 16:37:28

问题


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 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.



来源:https://stackoverflow.com/questions/17157816/postgresql-9-x-bytea-representation-in-hex-or-escape-for-thumbnail-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!