Skip to content
Cloudflare Docs

DuckDB

Below is an example of using DuckDB to connect to R2 Data Catalog (read-only). For more information on connecting to R2 Data Catalog with DuckDB, refer to DuckDB documentation.

Prerequisites

Example usage

In the DuckDB CLI (Command Line Interface), run the following commands:

-- Install the iceberg DuckDB extension (if you haven't already) and load the extension.
INSTALL iceberg;
LOAD iceberg;
-- Create a DuckDB secret to store R2 Data Catalog credentials.
CREATE SECRET r2_secret (
TYPE ICEBERG,
TOKEN '<token>'
);
-- Attach R2 Data Catalog with the following ATTACH statement (read-only).
ATTACH '<warehouse_name>' AS my_r2_catalog (
TYPE ICEBERG,
ENDPOINT '<catalog_uri>'
);
-- Show all available tables.
SHOW ALL TABLES;
-- Query your Iceberg table.
SELECT * FROM my_r2_catalog.default.my_iceberg_table;