gunzip
gunzip_pg · Decompress gzip-compressed bytea values to text or bytea.
Overview
PostgreSQL · 10
Usage
Sources:
gunzip exposes in-database decompression for gzip-compressed byte strings. Version 0.2 defines gunzip_text(bytea) for text output, gunzip_bytea(bytea) for binary output, and gunzip(bytea) as an alias of the text function.
Core workflow
Data and backend safety
Neither output function is binary-safe. Both use the C strlen result as the PostgreSQL datum length, so the first zero byte truncates the result; gunzip_bytea(bytea) therefore does not preserve arbitrary decompressed bytes. Accept only known NUL-free payloads and validate the result outside this extension.
The SQL functions are not strict while the C code does not check for a SQL NULL argument. Empty or malformed input returns NULL after a notice, allocation failure calls exit, and decompression grows a backend-local buffer without an output bound. A bad call can therefore terminate its backend, while a small compressed value can exhaust memory. Do not expose these functions to untrusted input. Version 0.2 is old and the catalog records PostgreSQL 10 coverage only; production use requires fixing these defects and testing the exact PostgreSQL and zlib versions.