delphi - 'hex' 或 'escape' 中的 PostgreSQL 9.X bytea 表示形式用于缩略图

标签 delphi postgresql bytea

我的应用程序(使用 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 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.

您似乎已经意识到 bytea_output .

关于delphi - 'hex' 或 'escape' 中的 PostgreSQL 9.X bytea 表示形式用于缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17157816/

相关文章:

mysql - 将查询 SQL 转换为 PostgreSQL

python - Psycopg2:cursor.execute 无法正常工作

java - 如何将数字转换为字节,类似于 postgres 中的 java

Delphi 获取具有滚动条的组件的实际全高/宽度

android - 如何将我的应用程序保留在前台?

database - 在 Delphi 的数据库中存储枚举的最佳方法是什么?

php - 如何使用 PHP 将 PostgreSQL bytea 值转换为数据 URL 值

delphi - AttachConsole 和 64 位应用程序

sql - 返回列与计数前 2 列匹配的所有行

postgresql - 如何使用 sqlalchemy 将数据从 postgres bytea 列中获取到 python 变量中?