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
- Query Farm hosting
- Available · $10/month organization minimum
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
| 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.
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;
INSTALL vgi FROM community;
LOAD vgi;
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'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'compress' AS compress (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-compress:0.5.0'
);
3. Run a query
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
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'compress' AS compress
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
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
Query Farm operates Compress for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use compress as the catalog alias for the query below.
4. Run a query
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
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
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]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'compress' AS compress (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-compress:0.5.0'
);
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.
Multi-codec (de)compression over a DuckDB BLOB column — zstd, gzip, zlib, deflate, brotli, lz4 (frame + block), snappy (framed + raw), xz, lzma, bzip2 — plus codec auto-detection by magic bytes, level control, and size/ratio introspection. Fills the one gap DuckDB core leaves open: core decompresses files, but there is no scalar to decode a column of compressed payloads at scan time. Decode a mixed-codec Kafka payload column, transcode a cold archive in place (gzip → zstd), or audit compression — all without leaving the engine.
Security — decompression bombs. Every decode path enforces a bounded max_output_bytes cap (default 256 MiB): a hostile high-ratio blob aborts that one row with a per-row error instead of OOMing the worker. Pure in-engine local CPU — no network, no state, zero egress.
Sources and references
- RFC 8878 — Zstandard
- RFC 1952 — gzip; RFC 1950 — zlib; RFC 1951 — DEFLATE
- RFC 7932 — Brotli
- LZ4 frame format — and the Snappy framing format
- The .xz file format — and bzip2
Catalog
Everything compress exposes once attached — read straight from the worker's
released build.
main 9 functions
Multi-codec compress / decompress / detect / introspect functions over a BLOB.
Schema 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;
| 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;
codecs ()
List the codec names this build supports
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;
| 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 |
compress (input ANY, codec VARCHAR, level ANY) +1 overload
Compress a BLOB with the given codec at the codec's default level
compress(input ANY, codec VARCHAR) → BLOBcompress(input ANY, codec VARCHAR, level ANY) → BLOB
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;
compressed_size (input ANY, codec VARCHAR, level ANY) +1 overload
Byte length of compress(input, codec) at the codec default level, without materializing the output
compressed_size(input ANY, codec VARCHAR) → UBIGINTcompressed_size(input ANY, codec VARCHAR, level ANY) → UBIGINT
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;
decompress (input ANY, codec VARCHAR, max_output_bytes ANY) +1 overload
Decompress a BLOB with the given codec (default bomb-guard output cap)
decompress(input ANY, codec VARCHAR) → BLOBdecompress(input ANY, codec VARCHAR, max_output_bytes ANY) → BLOB
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;
decompress_auto (input BLOB, max_output_bytes ANY) +1 overload
Auto-detect the codec by magic bytes and decompress (default bomb-guard cap)
decompress_auto(input BLOB) → BLOBdecompress_auto(input BLOB, max_output_bytes ANY) → BLOB
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;
decompressed_size (input ANY, codec VARCHAR, max_output_bytes ANY) +1 overload
Decompressed byte length of a compressed BLOB under the default output cap (NULL past it)
decompressed_size(input ANY, codec VARCHAR) → UBIGINTdecompressed_size(input ANY, codec VARCHAR, max_output_bytes ANY) → UBIGINT
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;
detect_codec (input ANY)
Return the codec name of a BLOB by magic bytes, or 'unknown'
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;
is_valid (input ANY, codec VARCHAR)
TRUE iff the BLOB is a well-formed stream for the codec (never errors)
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;
ratio (input ANY, codec VARCHAR, level ANY) +1 overload
Output-over-input compression ratio at the codec default level (< 1.0 means it shrank; NULL if empty)
ratio(input ANY, codec VARCHAR) → DOUBLEratio(input ANY, codec VARCHAR, level ANY) → DOUBLE
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;
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
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
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.
Related workers
Charset
File formats & encodings
Detect text encodings, convert legacy bytes to and from UTF-8, and repair mojibake
BSON
File formats & encodings
Query BSON documents and move them between files and tables
CBOR
File formats & encodings
Decode and encode CBOR and MessagePack, inspect security payloads, and import or export row files from SQL