Skip to content

Example of using ATTACH OR REPLACE in an API powered by DuckDB

License

Notifications You must be signed in to change notification settings

xevix/duckdb-attach-replace-api-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DuckDB ATTACH OR REPLACE in API

NOTE: unreleased feature, possibly will release with 1.3. Requires nightly builds for now. Uses TPCH, ensure you have ~256MB of disk space.

This demo shows how to make use of ATTACH OR REPLACE functionality in DuckDB to seamlessly switch to a newer upstream DB file. It uses a simple FastAPI-based service to wrap some basic DuckDB queries that generate and query TPCH data. First a v1 DuckDB file is queried, then a v2, but both use the same alias t which allows all queries to stay the same without needing to keep track of filenames or versions.

Example usage:

ATTACH OR REPLACE 'v1.duckdb' AS t
FROM t.lineitem;
-- Replace the alias
ATTACH OR REPLACE 'v2.duckdb' AS t
-- Alias is kept between attaches, so query can stay the same
FROM t.lineitem;

See: main.py.

Install

uv sync
uv run fastapi dev

Test

# Once API is up, generate files and run queries. Notice the values change after attaching v2.
sh ./test.sh

About

Example of using ATTACH OR REPLACE in an API powered by DuckDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published