Skip to content
ParquetKitGitHub
On this page

Guides

Open a CSV File Too Large for Excel with DuckDB

Why the usual tools fail

A 3 GB CSV export has two common outcomes. Excel loads the first 1,048,576 rows, warns that the rest did not load, and you have no way to know what was cut. A text editor tries to load the whole file into memory and freezes.

DuckDB avoids both problems. It queries the CSV where it sits, reads only what the query needs, and handles files larger than your RAM. You get a spreadsheet-like preview plus SQL to filter and summarize.

Preview the first rows

With the DuckDB CLI installed (a single binary from duckdb.org), you can query the file by name:

duckdb -c "SELECT * FROM 'export.csv' LIMIT 20"

The sniffer detects the delimiter, the header and the quoting, so semicolon or tab-separated files usually work unchanged. To see what it decided:

SELECT Delimiter, HasHeader, Columns FROM sniff_csv('export.csv');
DESCRIBE SELECT * FROM 'export.csv';

Wide tables are hard to read in the default box layout. In the interactive shell, .mode line prints one field per line, which is easier for checking a single record.

Answer questions without opening it

The whole point is not to scroll 40 million rows. Ask instead:

-- How many rows are there really?
SELECT count(*) FROM 'export.csv';

-- Only the rows you care about
SELECT * FROM 'export.csv'
WHERE country = 'DE' AND order_date >= DATE '2026-01-01'
LIMIT 100;

-- Per-column min, max, null % and distinct count
SUMMARIZE SELECT * FROM 'export.csv';

To get a slice that Excel can open, write the filtered result to a new file:

COPY (SELECT * FROM 'export.csv' WHERE country = 'DE')
TO 'export_de.csv' (HEADER);

When type detection gets it wrong

DuckDB infers types from a sample of rows, not the whole file. Two problems come up often.

A conversion error partway through the file. Every sampled value of qty is a number, but a row the sample missed contains N/A:

Conversion Error: CSV Error on Line: 2381907
Error when converting column "qty". Could not convert string "N/A" to 'BIGINT'

The error names the line, so you can see what is in the data. Then tell DuckDB what the value means, or set the type yourself:

SELECT * FROM read_csv('export.csv',
  nullstr = 'N/A',
  types = {'qty': 'INTEGER', 'customer_id': 'VARCHAR'});

If a few rows are malformed and you need to see them, collect them with store_rejects instead of skipping them:

SELECT * FROM read_csv('export.csv', store_rejects = true);
SELECT line, column_name, error_type, csv_line FROM reject_errors;

IDs that should stay text. Values with leading zeros such as 01234 are detected as VARCHAR. A long numeric ID without them becomes BIGINT, though, and loses formatting you may need. Declare those columns as VARCHAR in types, or use all_varchar = true to read everything as text while exploring.

Prefer a GUI?

duckdb -ui opens DuckDB's local web interface, which gives you a results grid for the same queries. If you would rather not install anything, the SQL Workbench runs the same engine in your browser. Drop the CSV in and query it by filename (SELECT * FROM 'export.csv' LIMIT 20). Nothing is uploaded.

If you will open it again, convert it once

Every query on a CSV re-parses text. If you will keep using the file, convert it to Parquet once. It ends up several times smaller, keeps the types you fixed above, and later queries run much faster:

COPY (SELECT * FROM read_csv('export.csv', types = {'customer_id': 'VARCHAR'}))
TO 'export.parquet' (FORMAT parquet, COMPRESSION zstd);

The CSV to Parquet converter does this in the browser, and the result opens instantly in the Parquet Viewer. For a folder of CSV files, see Combine Multiple CSV Files into One Parquet File. For the size and speed trade-offs, see Parquet vs CSV.

Frequently asked questions

Does DuckDB load the whole CSV into memory?
No. DuckDB streams the file. A LIMIT query reads only the first chunk, and aggregates like count(*) scan the file without holding all rows in memory, so files larger than RAM work.
Can DuckDB read a gzipped CSV directly?
Yes. Files ending in .csv.gz are decompressed on the fly, so SELECT * FROM 'export.csv.gz' LIMIT 20 works without unzipping first. Expect scans to be slower than on the uncompressed file.
Why does a query fail halfway through with a conversion error?
DuckDB guesses column types from a sample of rows. If a value deep in the file does not fit the guessed type, the scan fails at that line. Set the column type explicitly or use store_rejects to collect the bad rows.
Can I do this without installing DuckDB?
Yes. Drop the CSV into the SQL Workbench on parquetkit.com. It runs DuckDB in your browser through WebAssembly, so the same queries work and the file is never uploaded.

Related guides