Skip to content

Commit ebd6ef3

Browse files
committed
Add DuckDB example for R2 Data Catalog
1 parent 6833339 commit ebd6ef3

File tree

1 file changed

+42
-0
lines changed
  • src/content/docs/r2/data-catalog/config-examples

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: DuckDB
3+
pcx_content_type: example
4+
---
5+
6+
Below is an example of using [DuckDB](https://duckdb.org/) to connect to R2 Data Catalog (read-only). For more information on connecting to R2 Data Catalog with DuckDB, refer to [DuckDB documentation](https://duckdb.org/docs/stable/core_extensions/iceberg/iceberg_rest_catalogs#r2-catalog).
7+
8+
## Prerequisites
9+
10+
- Sign up for a [Cloudflare account](https://dash.cloudflare.com/sign-up/workers-and-pages).
11+
- [Create an R2 bucket](/r2/buckets/create-buckets/) and [enable the data catalog](/r2/data-catalog/manage-catalogs/#enable-r2-data-catalog-on-a-bucket).
12+
- [Create an R2 API token](/r2/api/tokens/) with both [R2 and data catalog permissions](/r2/api/tokens/#permissions).
13+
- Install [DuckDB](https://duckdb.org/docs/installation/).
14+
- Note: [DuckDB 1.3.0](https://github.com/duckdb/duckdb/releases/tag/v1.3.0) or greater is required to attach [Iceberg REST Catalogs](https://duckdb.org/docs/stable/core_extensions/iceberg/iceberg_rest_catalogs).
15+
16+
## Example usage
17+
18+
In the [DuckDB CLI](https://duckdb.org/docs/stable/clients/cli/overview.html) (Command Line Interface), run the following commands:
19+
20+
```sql
21+
-- Install the iceberg DuckDB extension (if you haven't already) and load the extension.
22+
INSTALL iceberg;
23+
LOAD iceberg;
24+
25+
-- Create a DuckDB secret to store R2 Data Catalog credentials.
26+
CREATE SECRET r2_secret (
27+
TYPE ICEBERG,
28+
TOKEN '<token>'
29+
);
30+
31+
-- Attach R2 Data Catalog with the following ATTACH statement (read-only).
32+
ATTACH '<warehouse_name>' AS my_r2_catalog (
33+
TYPE ICEBERG,
34+
ENDPOINT '<catalog_uri>'
35+
);
36+
37+
-- Show all available tables.
38+
SHOW ALL TABLES;
39+
40+
-- Query your Iceberg table.
41+
SELECT * FROM my_r2_catalog.default.my_iceberg_table;
42+
```

0 commit comments

Comments
 (0)