New SQL functions zstd_compress and zstd_decompress

The functions zstd_compress and zstd_decompress compress and decompress a blob using the Zstandard algorithm.

The functions are similar to zlib_compress and zlib_decompress. For text, Zstandard is generally more effective than Zlib or GZip while offering similar or higher speed.

How It Works

zstd_compress takes a blob and returns the Zstandard-compressed result as a blob. zstd_decompress does the opposite: it takes a Zstandard-compressed blob and returns the original content. Both functions accept exactly one parameter.

Example: Compression

The following example compresses a text and shows the result in base64:

select base64_encode(zstd_compress(ascii_to_blob('This text demonstrates how the function zstd_compress recognises repeated patterns and compresses them into a small result.')))

Resulting in:

KLUv/SB0rQIAQkcUFbClOee0JH6L7J1kWCbS5rCUuYxZBICjjQomdKKv+hHSWCs+pmb395p7s0GTmu3wlepxqgiaNNOY0AnBeA51uTBhUI/6SM1l6KtOn8avBwcCAA==

Example: Decompression

The following example decompresses the blob from the previous example and returns the original text:

select to_char(zstd_decompress('KLUv/SB0rQIAQkcUFbClOee0JH6L7J1kWCbS5rCUuYxZBICjjQomdKKv+hHSWCs+pmb395p7s0GTmu3wlepxqgiaNNOY0AnBeA51uTBhUI/6SM1l6KtOn8avBwcCAA=='))

Resulting in:

This text demonstrates how the function zstd_compress recognises repeated patterns and compresses them into a small result.

Availability

The SQL functions zstd_compress and zstd_decompress are available from release 27.0.