我的应用程序(使用 Delphi 和 ZEOS 组件开发)使用 PostgreSQL 8.4 并将一些缩略图图像存储到 bytea
列中。
我想迁移到 PostgreSQL 9.2 并恢复了转储,一切正常,除了当我尝试检索这些图像时:Postgres 9.2 使用 hex
作为输出表示而不是 escape
在 Postgres 8.4 中使用。
有两种可能的解决方案:更改 escape
表示的 Postgres 9.2 设置或通过应用程序更改二进制数据中的 hex
字符串。但最好的解决办法是什么?为什么 PostgreSQL 9.X 将 bytea
表示改为 hex
?
这是一个简单的设置还是有技术原因?
最佳答案
在 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.
您似乎已经意识到 bytea_output
.
关于delphi - 'hex' 或 'escape' 中的 PostgreSQL 9.X bytea 表示形式用于缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17157816/