+0
日增长
298
stars
55
forks
10
watchers
193
prs
93
issues
0
releases
README
DuckDB SQLite extension
The SQLite extension allows DuckDB to directly read and write data from a SQLite database file. The data can be queried directly from the underlying SQLite tables. Data can be loaded from SQLite tables into DuckDB tables, or vice versa.
Reading Data from SQLite
To make a SQLite file accessible to DuckDB, use the ATTACH command, for example with the bundled sakila.db file:
sql
ATTACH 'data/db/sakila.db' AS sakila;
USE sakila;
The tables in the file can be read as if they were normal DuckDB tables, but the underlying data is read directly from the SQLite tables in the file at query time.
sql
SHOW TABLES;
You can query the tables using SQL, e.g. using the example queries from sakila-examples.sql
sql
SELECT cat.name category_name,
Sum(Ifnull(pay.amount, 0)) revenue
FROM category cat
LEFT JOIN film_category flm_cat
ON cat.category_id = flm_cat.category_id
LEFT JOIN film fil
ON flm_cat.film_id = fil.film_id
LEFT JOIN inventory inv
ON fil.film_id = inv.film_id
LEFT JOIN rental ren
ON inv.inventory_id = ren.inventory_id
LEFT JOIN payment pay
ON ren.rental_id = pay.rental_id
GROUP BY cat.name
ORDER BY revenue DESC
LIMIT 5;
Opening SQLite Databases Directly
SQLite databases can also be opened directly and can be used transparently instead of a DuckDB database file. In any client, when connecting, a path to a SQLite database file can be provided and the SQLite database will be opened instead.
For example, with the shell:
sql
$ duckdb data/db/sakila.db
v0.9.1 401c8061c6
D SHOW tables;
┌────────────────────────┐
│ name │
│ varchar │
├────────────────────────┤
│ actor │
│ address │
│ category │
│ city │
│ country │
│ customer │
│ customer_list │
│ film │
│ film_actor │
│ film_category │
│ film_list │
│ film_text │
│ inventory │
│ language │
│ payment │
│ rental │
│ sales_by_film_category │
│ sales_by_store │
│ staff │
│ staff_list │
│ store │
├────────────────────────┤
│ 21 rows │
└────────────────────────┘
Writing Data to SQLite
In addition to reading data from SQLite, the extension also allows you to create new SQLite database files, create tables, ingest data into SQLite and make other modifications to SQLite database files using standard SQL queries.
This allows you to use DuckDB to, for example, export data that is stored in a SQLite database to Parquet, or read data from a Parquet file into SQLite.
Below is a brief example of how to create a new SQLite database and load data into it.
sql
ATTACH 'new_sqlite_database.db' AS sqlite_db (TYPE SQLITE);
CREATE TABLE sqlite_db.tTop issues
#80Can't build on an M1/ARM Mac6 comments · 2024-01-19#100db Loads in Windows but not Linux5 comments · 2024-06-01#145`ATTACH` fails with `~/some-db.sqlite3` path expansion3 comments · 2025-04-27#140Impossible to use this sqlite db3 comments · 2025-03-14#136Create table from another database results in errors and segfault3 comments · 2025-02-10#103COPY FROM DATABASE SQLite to DuckDB - Catalog Error2 comments · 2024-06-17#183Transaction starts prematurely during "did you mean" suggestion, causing database open failure1 comments · 2026-03-28#167COPY from one sqlite db to another does not work1 comments · 2025-11-18