Below is an example of using DuckDB ↗︎ to connect to Basin Catalog. For more information on connecting to Basin Catalog with DuckDB, refer to DuckDB documentation ↗︎.
- Sign up for a Cloudflare account ↗︎.
- Create an R2 bucket and enable the data catalog.
- Create an R2 API token with both R2 and data catalog permissions.
- Install DuckDB ↗︎.
- Note: DuckDB 1.4.0 ↗︎ or greater is required to attach and write to Iceberg REST Catalogs ↗︎.
- Note: DuckDB does not currently support ↗︎
DELETEon partitioned tables.
In the DuckDB CLI ↗︎ (Command Line Interface), run the following commands:
-- Install the Iceberg DuckDB extension if needed, then load the extension.
INSTALL iceberg;
LOAD iceberg;
-- Install and load httpfs extension for reading/writing files over HTTP(S).
INSTALL httpfs;
LOAD httpfs;
-- Create a DuckDB secret to store Basin Catalog credentials.
CREATE SECRET r2_secret (
TYPE ICEBERG,
TOKEN '<token>'
);
-- Attach Basin Catalog with the following ATTACH statement.
ATTACH '<warehouse_name>' AS my_r2_catalog (
TYPE ICEBERG,
ENDPOINT '<catalog_uri>'
);
-- Create the default schema in the catalog and set it as the active schema.
CREATE SCHEMA my_r2_catalog.default;
USE my_r2_catalog.default;
-- Create and populate a sample Iceberg table with data.
CREATE TABLE my_iceberg_table AS SELECT a FROM range(4) t(a);
-- Show all available tables.
SHOW ALL TABLES;
-- Query the Iceberg table you just created.
SELECT * FROM my_r2_catalog.default.my_iceberg_table;