pgadmin4 icon indicating copy to clipboard operation
pgadmin4 copied to clipboard

Add option to display binary data (`BYTEA`) as hex-encoded strings

Open fkellner opened this issue 9 months ago • 0 comments

Motivation

While the BYTEA-Datatype in Postgresql sounds like it should be used for BLOB storage, it can be useful in other contexts.

To give an example, an MD5 hash takes up about 22 Bytes of Storage when stored as NUMERIC, at 33 Bytes when stored as TEXT, but only 17 Bytes when stored as Bytea. In databases relying heavily on hashes and indexes on those hashes, using BYTEA therefore saves storage space and speeds up queries (There is some pressure from competitors here, in ORACLE databases, the NUMBER data type is as efficient as using BYTEA in Postgresql).

However, when developing a solution and trying to see at a glance if a query result is plausible, all those hash columns just display [binary data] if you forgot to add encode(..., 'hex') to them, resulting in a bad developer experience.

Solution I would like to see

To improve the developer experience when working with those bytea fields of quite limited length, it would be great if there was an option to display binary data as hex-encoded strings in the query output.

This could be a simple toggle in the Settings (File->Preferences->Query Tool->Results grid), and the resulting hex string could be treated like text and ellipsized if it reaches a certain length.

Alternatives I have considered

  • Migrating to storing hashes as strings purely to improve developer experience - resulting in a potentially significant storage and performance overhead
  • ~~Maybe I could use a macro? I tried to add one to find out how they work and if they can accomplish this, but the "add Macro" button did nothing~~ (Edit after reading the docs: I misunderstood what Macros do)

fkellner avatar Apr 08 '25 13:04 fkellner