Skip to content

Compress

Compress, decompress, and identify zstd, gzip, brotli, lz4, snappy, xz, and bzip2 payloads stored in BLOB columns

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/compress/index.md to help me query Compress with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

See what you can query

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT codec, compress.main.compressed_size(p, codec) AS bytes_out,
  round(compress.main.ratio(p, codec), 3) AS ratio
FROM (SELECT repeat('{"user":42,"event":"click","page":"/home"}' || chr(10), 200)::BLOB AS p),
     unnest(compress.main.codecs()) AS t(codec)
ORDER BY bytes_out, codec
Result · first 5 rows
codec bytes_out ratio
brotli 57 0.007
zstd 61 0.007
deflate 89 0.01
lz4_block 92 0.011
zlib 95 0.011

Quick start

Choose where to run Compress, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'compress' AS compress (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-compress'
);

3. Run a query

query.sql
SELECT codec, compress.main.compressed_size(p, codec) AS bytes_out,
  round(compress.main.ratio(p, codec), 3) AS ratio
FROM (SELECT repeat('{"user":42,"event":"click","page":"/home"}' || chr(10), 200)::BLOB AS p),
     unnest(compress.main.codecs()) AS t(codec)
ORDER BY bytes_out, codec
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'compress' AS compress (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Multi-codec (de)compression over a DuckDB BLOB column — zstd, gzip, zlib, deflate, brotli, lz4, snappy, xz, lzma, bzip2 — with codec auto-detection and a decompression-bomb guard.

Catalog

Everything compress exposes once attached — read straight from the worker's released build.

compress 1 schema
main 9 functions

Multi-codec compress / decompress / detect / introspect functions over a BLOB.

Schema examples (9)
Examples (9)

Decode a gzip'd HTTP body column to text at scan time.

SELECT compress.main.decompress(body_gz, 'gzip')::VARCHAR AS body
FROM http_logs;

Identify the codec of each message in a mixed-codec column.

SELECT id, compress.main.detect_codec(value) AS codec FROM kafka_messages;

Auto-detect and decode a mixed-codec column with a 64 MiB/row cap.

SELECT compress.main.decompress_auto(value, 67108864) AS payload
FROM kafka_messages;

Audit the zstd-19 compression ratio of a blob column.

SELECT avg(compress.main.ratio(blob, 'zstd', 19)) AS avg_ratio FROM report;
5 more examples

List every codec this build supports.

SELECT compress.main.codecs() AS codecs;

Rank every supported codec by compressed size and ratio on a sample JSON-lines payload, at each codec's default level (smallest output first).

SELECT codec, compress.main.compressed_size(p, codec) AS bytes_out,
  round(compress.main.ratio(p, codec), 3) AS ratio
FROM (SELECT repeat('{"user":42,"event":"click","page":"/home"}' || chr(10), 200)::BLOB AS p),
     unnest(compress.main.codecs()) AS t(codec)
ORDER BY bytes_out, codec;
Result · first 5 rows
codec bytes_out ratio
brotli 57 0.007
zstd 61 0.007
deflate 89 0.01
lz4_block 92 0.011
zlib 95 0.011

Profile a mixed-codec message column: group messages by the codec sniffed from their magic bytes and total stored vs. decompressed bytes per codec (the headerless brotli message is detected as 'unknown' and left out).

WITH inbox AS (SELECT id, compress.main.compress(repeat(body, 20)::BLOB, codec) AS payload FROM (VALUES (1, 'zstd', 'temp=21.5;'), (2, 'gzip', 'temp=22.0;'), (3, 'zstd', 'temp=20.9;'), (4, 'bzip2', 'temp=23.1;'), (5, 'brotli', 'temp=19.8;')) AS t(id, codec, body)), sniffed AS (SELECT payload, compress.main.detect_codec(payload) AS codec FROM inbox) SELECT codec, count(*) AS messages, sum(octet_length(payload)) AS stored_bytes, sum(compress.main.decompressed_size(payload, codec)) AS raw_bytes
FROM sniffed
WHERE codec <> 'unknown'
GROUP BY codec
ORDER BY codec;

Before transcoding a gzip archive to zstd, compare each file's current gzip size with the size its decompressed contents would take as zstd level 19 (nothing is rewritten).

WITH archive AS (SELECT name, compress.main.compress(repeat(line, n)::BLOB, 'gzip') AS gz FROM (VALUES ('access.log', 'GET /index.html 200' || chr(10), 300), ('error.log', 'WARN disk 91% full' || chr(10), 40)) AS t(name, line, n)) SELECT name, octet_length(gz) AS gzip_bytes, compress.main.compressed_size(compress.main.decompress(gz, 'gzip'), 'zstd', 19) AS zstd_bytes
FROM archive
ORDER BY name;

Triage payloads whose codec cannot be sniffed: for each blob detect_codec reports as 'unknown', list every supported codec it validates as a well-formed stream (the gzip blob is detectable, so it is skipped).

WITH uploads AS (SELECT id, compress.main.compress(body::BLOB, codec) AS payload FROM (VALUES (1, '{"status":"ok","items":[1,2,3]}', 'brotli'), (2, '{"status":"ok","items":[4,5,6]}', 'deflate'), (3, '{"status":"ok","items":[7,8,9]}', 'gzip')) AS t(id, body, codec)) SELECT id, codec
FROM uploads,
     unnest(compress.main.codecs()) AS t(codec)
WHERE compress.main.detect_codec(payload) = 'unknown' AND compress.main.is_valid(payload, codec)
ORDER BY id, codec;
Scalar functions
codecs () 3 examples

List the codec names this build supports

No arguments
ReturnsVARCHAR[]
Examples (3)

List every codec this build supports.

SELECT compress.main.codecs() AS codecs;

Check whether this build supports zstd.

SELECT list_contains(compress.main.codecs(), 'zstd') AS has_zstd;

Rank every supported codec by compressed size and ratio on a sample JSON-lines payload, at each codec's default level (smallest output first).

SELECT codec, compress.main.compressed_size(p, codec) AS bytes_out,
  round(compress.main.ratio(p, codec), 3) AS ratio
FROM (SELECT repeat('{"user":42,"event":"click","page":"/home"}' || chr(10), 200)::BLOB AS p),
     unnest(compress.main.codecs()) AS t(codec)
ORDER BY bytes_out, codec;
Result · first 5 rows
codec bytes_out ratio
brotli 57 0.007
zstd 61 0.007
deflate 89 0.01
lz4_block 92 0.011
zlib 95 0.011
Link
compress (input ANY, codec VARCHAR, level ANY) +1 overload 4 examples

Compress a BLOB with the given codec at the codec's default level

Arguments
input ANY
The payload to compress — one row's worth of bytes.
codec VARCHAR
The codec name (case-insensitive): zstd, gzip, zlib, deflate, brotli, lz4, lz4_block, snappy, snappy_raw, xz, lzma, bzip2.
level ANY
Compression level. NULL → the codec default; out-of-range clamps to the codec's range; ignored for level-less codecs (snappy/snappy_raw).
Overloads
compress(input ANY, codec VARCHAR) → BLOBcompress(input ANY, codec VARCHAR, level ANY) → BLOB
ReturnsBLOB
Examples (4)

Compress a blob with gzip at the default level.

SELECT compress.main.compress('the quick brown fox'::BLOB, 'gzip') AS packed;

Compress a blob with zstd at level 19.

SELECT compress.main.compress('the quick brown fox'::BLOB, 'zstd', 19) AS packed;
SELECT compress.main.decompress(compress.main.compress('hello, world'::BLOB, 'gzip'), 'gzip')::VARCHAR AS roundtrip;
1 more example
SELECT compress.main.detect_codec(compress.main.compress('payload'::BLOB, 'zstd')) AS codec;
Link
compressed_size (input ANY, codec VARCHAR, level ANY) +1 overload 2 examples

Byte length of compress(input, codec) at the codec default level, without materializing the output

Arguments
input ANY
The payload whose compressed size to measure.
codec VARCHAR
The codec to compress with.
level ANY
Compression level (NULL → codec default; out-of-range clamps; ignored for level-less codecs).
Overloads
compressed_size(input ANY, codec VARCHAR) → UBIGINTcompressed_size(input ANY, codec VARCHAR, level ANY) → UBIGINT
ReturnsUBIGINT
Examples (2)

How many bytes would this blob occupy as gzip at the default level?

SELECT compress.main.compressed_size('the quick brown fox'::BLOB, 'gzip') AS bytes_out;

How many bytes would this blob occupy as zstd at level 19?

SELECT compress.main.compressed_size('the quick brown fox'::BLOB, 'zstd', 19) AS bytes_out;
Link
decompress (input ANY, codec VARCHAR, max_output_bytes ANY) +1 overload 3 examples

Decompress a BLOB with the given codec (default bomb-guard output cap)

Arguments
input ANY
The compressed payload to decode.
codec VARCHAR
The codec the input is compressed with (case-insensitive): zstd, gzip, zlib, deflate, brotli, lz4, lz4_block, snappy, snappy_raw, xz, lzma, bzip2.
max_output_bytes ANY
Decompression-bomb guard: abort the row if decoded output would exceed this many bytes. NULL → the worker default cap (compress_max_output_bytes, 256 MiB).
Overloads
decompress(input ANY, codec VARCHAR) → BLOBdecompress(input ANY, codec VARCHAR, max_output_bytes ANY) → BLOB
ReturnsBLOB
Examples (3)

Decompress a gzip blob and cast the bytes back to text.

SELECT compress.main.decompress(compress.main.compress('hi'::BLOB, 'gzip'), 'gzip')::VARCHAR AS body;

Decompress a gzip blob with a 64 MiB output cap.

SELECT compress.main.decompress(compress.main.compress('hi'::BLOB, 'gzip'), 'gzip', 67108864) AS body;

Before transcoding a gzip archive to zstd, compare each file's current gzip size with the size its decompressed contents would take as zstd level 19 (nothing is rewritten).

WITH archive AS (SELECT name, compress.main.compress(repeat(line, n)::BLOB, 'gzip') AS gz FROM (VALUES ('access.log', 'GET /index.html 200' || chr(10), 300), ('error.log', 'WARN disk 91% full' || chr(10), 40)) AS t(name, line, n)) SELECT name, octet_length(gz) AS gzip_bytes, compress.main.compressed_size(compress.main.decompress(gz, 'gzip'), 'zstd', 19) AS zstd_bytes
FROM archive
ORDER BY name;
Link
decompress_auto (input BLOB, max_output_bytes ANY) +1 overload 2 examples

Auto-detect the codec by magic bytes and decompress (default bomb-guard cap)

Arguments
input BLOB
The compressed payload to auto-detect (by magic bytes) and decode.
max_output_bytes ANY
Decompression-bomb guard: abort the row if decoded output would exceed this many bytes. NULL → the worker default cap (compress_max_output_bytes, 256 MiB).
Overloads
decompress_auto(input BLOB) → BLOBdecompress_auto(input BLOB, max_output_bytes ANY) → BLOB
ReturnsBLOB
Examples (2)

Auto-detect the codec by magic bytes and decompress a blob to text.

SELECT compress.main.decompress_auto(compress.main.compress('hi'::BLOB, 'gzip'))::VARCHAR AS plaintext;

Auto-detect and decompress a gzip blob with a 64 MiB/row output cap.

SELECT compress.main.decompress_auto(compress.main.compress('hi'::BLOB, 'gzip'), 67108864) AS plaintext;
Link
decompressed_size (input ANY, codec VARCHAR, max_output_bytes ANY) +1 overload 2 examples

Decompressed byte length of a compressed BLOB under the default output cap (NULL past it)

Arguments
input ANY
The compressed payload whose decoded size to measure.
codec VARCHAR
The codec the input is compressed with.
max_output_bytes ANY
Bomb-guard cap; return NULL rather than decode past this many bytes. NULL → the worker default (256 MiB).
Overloads
decompressed_size(input ANY, codec VARCHAR) → UBIGINTdecompressed_size(input ANY, codec VARCHAR, max_output_bytes ANY) → UBIGINT
ReturnsUBIGINT
Examples (2)

How big does this gzip blob expand to?

SELECT compress.main.decompressed_size(compress.main.compress('the quick brown fox'::BLOB, 'gzip'), 'gzip') AS bytes;

How big does this gzip blob expand to, under a 64 MiB cap?

SELECT compress.main.decompressed_size(compress.main.compress('the quick brown fox'::BLOB, 'gzip'), 'gzip', 67108864) AS bytes;
Link
detect_codec (input ANY) 2 examples

Return the codec name of a BLOB by magic bytes, or 'unknown'

Arguments
input ANY
The payload to identify by magic bytes. Headerless codecs return 'unknown'.
ReturnsVARCHAR
Examples (2)

Identify the codec of a compressed blob from its magic bytes.

SELECT compress.main.detect_codec(compress.main.compress('hi'::BLOB, 'zstd')) AS codec;

Profile a mixed-codec message column: group messages by the codec sniffed from their magic bytes and total stored vs. decompressed bytes per codec (the headerless brotli message is detected as 'unknown' and left out).

WITH inbox AS (SELECT id, compress.main.compress(repeat(body, 20)::BLOB, codec) AS payload FROM (VALUES (1, 'zstd', 'temp=21.5;'), (2, 'gzip', 'temp=22.0;'), (3, 'zstd', 'temp=20.9;'), (4, 'bzip2', 'temp=23.1;'), (5, 'brotli', 'temp=19.8;')) AS t(id, codec, body)), sniffed AS (SELECT payload, compress.main.detect_codec(payload) AS codec FROM inbox) SELECT codec, count(*) AS messages, sum(octet_length(payload)) AS stored_bytes, sum(compress.main.decompressed_size(payload, codec)) AS raw_bytes
FROM sniffed
WHERE codec <> 'unknown'
GROUP BY codec
ORDER BY codec;
Link
is_valid (input ANY, codec VARCHAR) 2 examples

TRUE iff the BLOB is a well-formed stream for the codec (never errors)

Arguments
input ANY
The payload to test for well-formedness.
codec VARCHAR
The codec to validate against.
ReturnsBOOLEAN
Examples (2)

Check whether a blob is a well-formed gzip stream.

SELECT compress.main.is_valid(compress.main.compress('hi'::BLOB, 'gzip'), 'gzip') AS ok;

Triage payloads whose codec cannot be sniffed: for each blob detect_codec reports as 'unknown', list every supported codec it validates as a well-formed stream (the gzip blob is detectable, so it is skipped).

WITH uploads AS (SELECT id, compress.main.compress(body::BLOB, codec) AS payload FROM (VALUES (1, '{"status":"ok","items":[1,2,3]}', 'brotli'), (2, '{"status":"ok","items":[4,5,6]}', 'deflate'), (3, '{"status":"ok","items":[7,8,9]}', 'gzip')) AS t(id, body, codec)) SELECT id, codec
FROM uploads,
     unnest(compress.main.codecs()) AS t(codec)
WHERE compress.main.detect_codec(payload) = 'unknown' AND compress.main.is_valid(payload, codec)
ORDER BY id, codec;
Link
ratio (input ANY, codec VARCHAR, level ANY) +1 overload 2 examples

Output-over-input compression ratio at the codec default level (< 1.0 means it shrank; NULL if empty)

Arguments
input ANY
The payload whose compression ratio to measure.
codec VARCHAR
The codec to compress with.
level ANY
Compression level (NULL → codec default; out-of-range clamps; ignored for level-less codecs).
Overloads
ratio(input ANY, codec VARCHAR) → DOUBLEratio(input ANY, codec VARCHAR, level ANY) → DOUBLE
ReturnsDOUBLE
Examples (2)

What compression ratio does gzip achieve on this blob at the default level?

SELECT compress.main.ratio('the quick brown fox jumps'::BLOB, 'gzip') AS ratio;

What compression ratio does zstd at level 19 achieve on this blob?

SELECT compress.main.ratio('the quick brown fox jumps'::BLOB, 'zstd', 19) AS ratio;
Link

Try these queries

Decode a gzip'd HTTP body column to text at scan time.

SELECT compress.main.decompress(body_gz, 'gzip')::VARCHAR AS body
FROM http_logs

Uses decompress

Identify the codec of each message in a mixed-codec column.

SELECT id, compress.main.detect_codec(value) AS codec FROM kafka_messages

Uses detect_codec

Auto-detect and decode a mixed-codec column with a 64 MiB/row cap.

SELECT compress.main.decompress_auto(value, 67108864) AS payload
FROM kafka_messages

Uses decompress_auto

Audit the zstd-19 compression ratio of a blob column.

SELECT avg(compress.main.ratio(blob, 'zstd', 19)) AS avg_ratio FROM report

Uses ratio

List every codec this build supports.

SELECT compress.main.codecs() AS codecs

Uses codecs

Profile a mixed-codec message column: group messages by the codec sniffed from their magic bytes and total stored vs. decompressed bytes per codec (the headerless brotli message is detected as 'unknown' and left out).

WITH inbox AS (SELECT id, compress.main.compress(repeat(body, 20)::BLOB, codec) AS payload FROM (VALUES (1, 'zstd', 'temp=21.5;'), (2, 'gzip', 'temp=22.0;'), (3, 'zstd', 'temp=20.9;'), (4, 'bzip2', 'temp=23.1;'), (5, 'brotli', 'temp=19.8;')) AS t(id, codec, body)), sniffed AS (SELECT payload, compress.main.detect_codec(payload) AS codec FROM inbox) SELECT codec, count(*) AS messages, sum(octet_length(payload)) AS stored_bytes, sum(compress.main.decompressed_size(payload, codec)) AS raw_bytes
FROM sniffed
WHERE codec <> 'unknown'
GROUP BY codec
ORDER BY codec

Uses compressdetect_codecdecompressed_size

19 more examples in the Catalog, each listed under the table or function it uses.

Compress is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.