On this page
Convert a SQLite Database to Parquet Files with DuckDB
Why move SQLite data to Parquet
SQLite is great as an application database and awkward as an analytics
source. Scans are row-by-row, the file is often locked by the app writing
to it, and most data tools can't read .db files at all. Parquet is
columnar and compressed, and DuckDB, Spark, Polars, BigQuery and pandas
all read it. DuckDB is also the shortest path between the two formats.
One table
Install the extension once, attach the database, and copy:
INSTALL sqlite;
LOAD sqlite;
ATTACH 'app.db' AS src (TYPE SQLITE, READ_ONLY);
COPY src.orders TO 'orders.parquet' (FORMAT parquet, COMPRESSION zstd);
From the shell, that's one line:
duckdb -c "ATTACH 'app.db' AS src (TYPE SQLITE, READ_ONLY);
COPY src.orders TO 'orders.parquet' (FORMAT parquet, COMPRESSION zstd)"
If you'd rather not attach, sqlite_scan('app.db', 'orders') reads a
single table as a table function.
Every table at once
To list what's in the file:
SELECT table_name FROM duckdb_tables() WHERE database_name = 'src';
To export all of it, EXPORT DATABASE writes one Parquet file per table
plus schema.sql and load.sql scripts:
EXPORT DATABASE src TO 'export_dir' (FORMAT parquet);
One bad table stops the whole export, so if it fails, deal with the type errors below first.
Fix the types before you write
SQLite stores whatever you give it, whatever the column says. DuckDB maps
each column from its declared type, so check DESCRIBE src.orders before
exporting. Typical surprises:
| SQLite declaration | DuckDB reads it as | What to do |
|---|---|---|
INTEGER, REAL, TEXT | BIGINT, DOUBLE, VARCHAR | nothing |
DATETIME with ISO text | TIMESTAMP | nothing |
BOOLEAN | BIGINT (0/1) | paid::BOOLEAN |
| no declared type | BLOB | cast to VARCHAR or a number |
INTEGER holding Unix seconds | BIGINT | to_timestamp(created) |
REAL holding money | DOUBLE | CAST(amount AS DECIMAL(18,2)) |
Write the casts into the export query rather than fixing them later:
COPY (
SELECT id,
CAST(amount AS DECIMAL(18,2)) AS amount,
created_at,
paid::BOOLEAN AS paid,
CAST(note AS VARCHAR) AS note
FROM src.orders
) TO 'orders.parquet' (FORMAT parquet, COMPRESSION zstd);
to_timestamp returns TIMESTAMP WITH TIME ZONE. Add ::TIMESTAMP if
downstream tools expect naive timestamps.
"Mismatch Type Error: Invalid type in column"
This is the error you'll hit on older databases:
Mismatch Type Error: Invalid type in column "n": column was declared as
integer, found "oops" of type "text" instead.
Some row holds a value that doesn't match the declared type. Read everything as text, find the offenders, then decide:
SET sqlite_all_varchar = true;
SELECT n FROM src.bad WHERE TRY_CAST(n AS BIGINT) IS NULL AND n IS NOT NULL;
COPY (SELECT TRY_CAST(n AS BIGINT) AS n FROM src.bad)
TO 'bad.parquet' (FORMAT parquet);
TRY_CAST turns bad values into NULL. Only use it once you've looked at
what's being dropped.
Check the result
Compare row counts between source and output:
SELECT (SELECT count(*) FROM src.orders) AS sqlite_rows,
(SELECT count(*) FROM 'orders.parquet') AS parquet_rows;
Then open orders.parquet in the Parquet Viewer to
check the schema and the first rows. Everything runs locally in your
browser and nothing is uploaded. For follow-up questions, query it in the
SQL Workbench. If someone downstream needs a spreadsheet,
Parquet to CSV covers that step. For the reverse
direction, see
loading Parquet into DuckDB or SQLite.
Frequently asked questions
- Can I convert SQLite to Parquet without pandas?
- Yes. DuckDB's sqlite extension attaches the .db file directly, and a single COPY statement writes a table to Parquet. No intermediate CSV and no Python are needed.
- How do I fix 'Mismatch Type Error: Invalid type in column'?
- SQLite let a value of a different type into a typed column. Run SET sqlite_all_varchar = true to read every column as text, then cast the columns you care about to proper types in the SELECT.
- Why is my BOOLEAN column an integer in the Parquet file?
- SQLite has no boolean storage class, so DuckDB reads a column declared BOOLEAN as BIGINT holding 0 and 1. Cast it with paid::BOOLEAN before writing the Parquet file.
- Does this modify my SQLite file?
- No, reading never writes to it. To be certain, attach the file with the READ_ONLY option so no statement can change it by accident.