Skip to Content
GuidesDuckDB + Apache Iceberg

DuckDB + Apache Iceberg

This guide covers Apache Iceberg from DuckDB end to end: attaching a catalog, reading, writing, time travel, schema changes, compaction, and the errors you are most likely to hit. Everything in the first part is plain open-source DuckDB. The last section shows the same thing on Thunderduck, where the setup is done for you.

We ran the examples on DuckDB 1.5.6 and 2.0.1, against two Iceberg REST catalogs on a laptop: Apache’s apache/iceberg-rest-fixture and Nessie 0.108, both storing files in MinIO. Where the two versions or the two catalogs behave differently, the text says so, and the few statements we did not run are marked. AWS Glue has its own traps and its own guide: DuckDB + Apache Iceberg on AWS Glue.

Two ways to use Iceberg from DuckDB

Attached catalogDirect read
HowATTACH … (TYPE iceberg), then catalog.schema.tableiceberg_scan('s3://…/metadata/….metadata.json')
Needs a catalogYes, an Iceberg REST catalogNo
ReadsYesYes
WritesYesNo
Knows the current versionYes, the catalog says which metadata file is currentOnly if you tell it

Use an attached catalog whenever you have one. Direct reads are for a table somebody handed you as a folder; they are covered near the end.

1. Load the extensions

INSTALL iceberg; LOAD iceberg; INSTALL httpfs; LOAD httpfs;

iceberg talks to the catalog and reads the table metadata. httpfs reads and writes the data files in S3-compatible storage. On AWS, also install aws, which provides PROVIDER credential_chain for the storage secret. DuckDB autoloads all three on first use, but that is a download in the middle of your first query.

2. Attach a catalog

An Iceberg setup has two sets of credentials, and DuckDB needs both:

  • Storage: an S3 secret, used to read and write the Parquet files. Some catalogs, Cloudflare Basin among them, hand out storage credentials per table instead (vended credentials), and then you do not create one.
  • Catalog: how DuckDB authenticates to the REST catalog itself.
-- Storage: on AWS, the identity the process already has CREATE SECRET lake_storage ( TYPE s3, PROVIDER credential_chain, REGION 'us-east-1' ); -- Catalog: a local REST catalog with no authentication ATTACH '' AS lake ( TYPE iceberg, ENDPOINT 'http://localhost:8181', AUTHORIZATION_TYPE 'none' );

The first argument of ATTACH is the warehouse name. The fixture catalog has one unnamed warehouse, so it is empty here; most hosted catalogs want a name. For MinIO or another S3-compatible store, the storage secret takes static keys and an endpoint: KEY_ID, SECRET, ENDPOINT 'localhost:9000', URL_STYLE 'path', USE_SSL false.

lake is now an attached database. Each Iceberg namespace is a schema in it.

Use ENDPOINT, not URI, if you are on 1.5. DuckDB’s 2.0 documentation writes the catalog address as URI '…'. On 1.5.6 that fails with Unhandled options found: uri. ENDPOINT works on both versions.

Other catalogs

-- A REST catalog with OAuth2: the general case CREATE SECRET lake_catalog ( TYPE iceberg, CLIENT_ID '…', CLIENT_SECRET '…', OAUTH2_SERVER_URI 'https://catalog.example.com/v1/oauth/tokens' ); ATTACH 'warehouse' AS lake ( TYPE iceberg, ENDPOINT 'https://catalog.example.com', SECRET lake_catalog ); -- A REST catalog with a bearer token, such as Cloudflare Basin -- (formerly R2 Data Catalog) CREATE SECRET basin_token (TYPE iceberg, TOKEN '…'); ATTACH 'warehouse' AS basin ( TYPE iceberg, ENDPOINT 'https://catalog.cloudflarestorage.com/…', SECRET basin_token ); -- AWS Glue and Amazon S3 Tables: requests are signed with the S3 secret ATTACH ':' AS glue (TYPE iceberg, ENDPOINT_TYPE 'glue'); ATTACH 'arn:aws:s3tables:…' AS s3t (TYPE iceberg, ENDPOINT_TYPE s3_tables); -- Nessie, without authentication ATTACH 'warehouse' AS nessie ( TYPE iceberg, ENDPOINT 'http://localhost:19120/iceberg', AUTHORIZATION_TYPE 'none', ACCESS_DELEGATION_MODE 'none' );

Thunderduck runs Glue, Nessie and Basin catalogs in production, and we ran the local fixture and Nessie for this guide. The OAuth2 and S3 Tables statements are taken from DuckDB’s catalog documentation , which also covers Polaris, Lakekeeper and BigLake. Glue has its own guide, and Nessie needs the last option for a reason explained below.

3. Create and read tables

CREATE SCHEMA lake.shop; CREATE TABLE lake.shop.orders AS SELECT range AS order_id, (range // 330) % 1000 AS customer_id, ((range * 37) % 20000 / 100.0)::DECIMAL(10,2) AS amount, DATE '2026-01-01' + (range % 330)::INT AS order_date FROM range(1_000_000); SHOW TABLES FROM lake.shop; SELECT order_date, count(*) AS orders, sum(amount) AS revenue FROM lake.shop.orders WHERE order_date >= DATE '2026-11-24' GROUP BY 1 ORDER BY 1;

The CREATE TABLE … AS writes one Parquet file with 1 million rows and commits the table’s first snapshot. The query returns three days of 3,030 orders each: 303,163.20, 303,084.30 and 303,005.40 in revenue.

DESCRIBE, SHOW ALL TABLES and information_schema.tables all work on an attached REST catalog. SHOW TABLES FROM lake.no_such_schema returns no rows instead of an error, so check the name when a schema looks empty.

4. Change data: INSERT, UPDATE, DELETE, MERGE

All four work on an attached catalog, in both versions:

INSERT INTO lake.shop.orders VALUES (1000000, 7, 19.99, DATE '2026-11-27'); UPDATE lake.shop.orders SET amount = 24.99 WHERE order_id = 1000000; DELETE FROM lake.shop.orders WHERE customer_id = 7; MERGE INTO lake.shop.orders AS t USING ( SELECT * FROM (VALUES (0, 0, 1.00::DECIMAL(10,2), DATE '2026-01-01'), (2000000, 8, 2.00::DECIMAL(10,2), DATE '2026-11-27') ) v(order_id, customer_id, amount, order_date) ) AS s ON t.order_id = s.order_id WHEN MATCHED THEN UPDATE SET amount = s.amount WHEN NOT MATCHED THEN INSERT VALUES (s.order_id, s.customer_id, s.amount, s.order_date);

Nothing is rewritten in place. This is what each statement left behind:

StatementRows changedSnapshotsData filesDelete files
CREATE TABLE … AS1,000,000110
INSERT1220
UPDATE1331
DELETE1,321433
MERGE25 (6 on 1.5.6)54

The table now holds 998,681 rows in five data files, with four delete files that mark 1,323 rows as removed.

  • Every statement is a snapshot. A MERGE that both updates and inserts takes two snapshots on 1.5.6 and one on 2.0.1. Wrapping statements in BEGIN … COMMIT does not merge them: two inserts in one transaction still left two snapshots and two files, on both versions.
  • Updates and deletes are merge-on-read by default. DuckDB writes position delete files that mark rows as removed, and an UPDATE adds the new row versions as a new data file. The original files stay as they are, and every later read applies the deletes.
  • Copy-on-write depends on the version. With the table property write.delete.mode set to copy-on-write, 1.5.6 refuses the DELETE: DuckDB-Iceberg only supports merge-on-read for updates/deletes. 2.0.1 ran it and rewrote the data file, with no delete file. DuckDB’s 2.0 documentation still lists copy-on-write as unsupported, so treat that as undocumented behaviour.
  • 2.0 returns row counts. DELETE answers 1321 on 2.0.1 and nothing on 1.5.6.
  • UPDATE and DELETE also ran on a partitioned table in both versions.

5. Partitioned tables

CREATE TABLE lake.shop.orders_by_month ( order_id BIGINT, customer_id BIGINT, amount DECIMAL(10,2), order_date DATE ) PARTITIONED BY (month(order_date));

The transforms are Iceberg’s: a column by itself, year, month, day, hour, bucket(n, col) and truncate(w, col), and both versions accepted all of them. Loading the same 1 million orders writes 11 files, one per month.

-- Reads 1 of 11 files SELECT sum(amount) FROM lake.shop.orders_by_month WHERE order_date = DATE '2026-06-15'; -- Reads all 11 SELECT sum(amount) FROM lake.shop.orders_by_month WHERE customer_id = 42;

EXPLAIN ANALYZE shows Total Files Read: 1 for the first query and 11 for the second. The filter is on order_date, not on a partition column: Iceberg partitioning is hidden, so queries never mention the month. A filter on any other column can still skip files through their min/max statistics, but only if the data is sorted so that those ranges do not overlap.

6. Snapshots and time travel

SELECT sequence_number, snapshot_id, timestamp_ms FROM iceberg_snapshots('lake.shop.orders') ORDER BY sequence_number; -- The table as of a snapshot SELECT count(*), sum(amount) FROM lake.shop.orders AT (VERSION => 5341568879365996703); -- The table as of a moment SELECT count(*) FROM lake.shop.orders AT (TIMESTAMP => TIMESTAMP '2026-11-27 03:42:21.236');

Snapshot ids are different on every table; copy yours from iceberg_snapshots. Against the first snapshot the count is 1,000,000 and the sum 99,995,000.00, the table before any of the changes above. The current table sums to 99,859,257.20.

iceberg_metadata('lake.shop.orders') lists the files behind the current snapshot, one row per data or delete file, with its row count.

7. Change the schema

ALTER TABLE lake.shop.orders ADD COLUMN channel VARCHAR; ALTER TABLE lake.shop.orders RENAME COLUMN channel TO sales_channel;

Schema changes are metadata only. Neither statement added a snapshot or touched a data file, and all 998,681 existing rows read NULL for the new column. DROP COLUMN and ALTER COLUMN … TYPE work the same way. Iceberg tracks columns by id, so a rename does not confuse old files.

8. Small files and compaction

Twenty single-row inserts later, the table has 25 data files, 4 delete files and 20 more snapshots. Every read now opens all of them.

DuckDB 2.0 can compact a table itself:

CALL iceberg_rewrite_data_files('lake.shop.orders', min_input_files => 2);

On our table it rewrote 25 data files into 1 and removed all 4 delete files, in one new snapshot. The row count stayed at 998,701.

2.0 can also move a table back to an earlier snapshot:

CALL iceberg_rollback_to_snapshot('lake.shop.orders', 5341568879365996703);

After that the table read 1,000,000 rows again.

Neither function exists in 1.5.6 (Table Function with name iceberg_rewrite_data_files does not exist). There, compaction needs another engine, such as Spark’s rewrite_data_files, or a rebuild with CREATE TABLE … AS SELECT. Neither version has a function to expire old snapshots, so their files stay in storage until another tool removes them.

What differs between 1.5 and 2.0

DuckDB 1.5.6DuckDB 2.0.1
CREATE TABLE, INSERT, UPDATE, DELETE, MERGE INTOYesYes
ALTER TABLE add, rename, drop columnYesYes
PARTITIONED BY, time travel with ATYesYes
Catalog address in ATTACHENDPOINT onlyENDPOINT or URI
Row count returned by INSERT, UPDATE, DELETENoYes
Snapshots for a MERGE that updates and inserts21
DELETE on a table set to copy-on-writeRefusedRewrites the data file
iceberg_rewrite_data_files (compaction)NoYes
iceberg_rollback_to_snapshotNoYes

Reading a table without a catalog

iceberg_scan reads a table from its files. Point it at a metadata file:

SELECT count(*) FROM iceberg_scan('s3://lake/rest/shop/orders_by_month/metadata/00001-988cd17b-45b7-452a-a376-d925ddea6da6.metadata.json');

Pointing it at the table folder fails unless the folder has a version-hint.text file, which neither of our catalogs wrote:

Failed to read iceberg table. No version was provided and no version-hint could be found, globbing the filesystem to locate the latest version is disabled by default as this is considered unsafe and could result in reading uncommitted data.

SET unsafe_enable_version_guessing = true makes DuckDB guess the latest metadata file from the file names. The name is honest. On the fixture catalog, metadata files are numbered 00000-, 00001-, and the guess was right. On Nessie every metadata file starts with 00000- followed by a random id, and in one of our two runs the guess read an old version: 1,000,002 rows, when the catalog said 998,683.

Direct reads are read-only. Writing needs a catalog, because a commit is a change to the catalog’s pointer.

Nessie differences

Three things behaved differently on Nessie than on the fixture catalog:

  • Vended credentials. With an S3 secret in place and the default ATTACH options, CREATE TABLE failed with Could not refresh Iceberg vended credentials for table 'orders': … Table does not exist. Adding ACCESS_DELEGATION_MODE 'none' to the ATTACH fixed it, on both versions. So did configuring storage with SET s3_endpoint = … and the other s3_ settings in place of a secret.
  • One snapshot in the list. iceberg_snapshots returned only the current snapshot, whatever the number of writes. Nessie keeps the table’s history itself, as commits on a branch, so AT (VERSION => …) has no older snapshot ids to work with.
  • Table folders get a suffix. lake.shop.orders is stored under …/shop/orders_<uuid>/, so you cannot build the path from the table name.

Errors and fixes

HTTP 403 on the first write

HTTP Error: HTTP PUT error uploading to 's3://lake/rest/shop/orders/data/….parquet' (HTTP 403 Forbidden)

The catalog accepted the request and the storage did not: there is no S3 secret, or it does not cover this bucket. 1.5.6 words it as Unable to connect to URL s3://… : Forbidden (HTTP code 403). Create the storage secret, and see DuckDB + Amazon S3 for the ways an S3 secret goes wrong.

Unhandled options found: uri

You are on 1.5 and followed a 2.0 example. Write ENDPOINT in the ATTACH.

Could not refresh Iceberg vended credentials

DuckDB asked the catalog for storage credentials for a table that does not exist yet. Add ACCESS_DELEGATION_MODE 'none' to the ATTACH so DuckDB uses your own S3 secret. We hit this on Nessie; see above.

Cannot execute statement of type “INSERT” … attached in read-only mode

The catalog was attached with READ_ONLY. Attach it again without that option.

Location information cannot be null

That one is AWS Glue, which wants a storage location for every new table. The fix is in the Glue guide.

The same thing on Thunderduck

Thunderduck runs DuckDB with this setup already done. Three catalog types hold Iceberg tables: Iceberg on AWS Glue, a Nessie server you run, and Cloudflare Basin. You add one once, and every query after that:

  • has no extensions, secrets or ATTACH. They are in place for every query, and those statements are refused if you send them.
  • writes with ordinary SQL. CREATE TABLE … AS SELECT, INSERT, UPDATE and DELETE work, from any source you have connected. MERGE and explicit transactions are not accepted.
  • gets its table locations for free. On Glue, Thunderduck derives each table’s location under the catalog’s own prefix.
  • is maintained by LakeOps. Glue and Nessie tables are compacted daily to a 512 MiB target file size, and Glue snapshots older than seven days are expired. You do not run iceberg_rewrite_data_files yourself.
  • runs in its own DuckDB worker, sized from the query plan, that can only reach your own catalogs.
-- catalog "lake" is Iceberg on Glue; "sales_pg" is a PostgreSQL catalog CREATE TABLE lake.default.orders_daily AS SELECT date_trunc('day', created_at) AS day, count(*) AS orders FROM sales_pg.public.orders GROUP BY 1; SELECT * FROM lake.default.orders_daily ORDER BY day DESC LIMIT 7;

iceberg_snapshots and iceberg_metadata are available too, but they take the table’s storage path, not its catalog name. See Accepted SQL for the exact rules, and each catalog’s page for its own limits.