Database6 min

Query CSV Files with SQL in Your Browser (DuckDB-WASM Tutorial)

Run real SQL — joins, GROUP BY, window functions — against local CSV files using DuckDB-WASM. No database install, no upload, no server.

DuckDB-WASM runs entirely inside your browser via Zro7 SQL Playground. Your CSV never leaves the tab.

To query a CSV file with SQL in the browser, open Zro7 SQL Playground, drop the file, and run SELECT * FROM my_file LIMIT 100. It's powered by DuckDB-WASM — a full analytical SQL engine compiled to WebAssembly — so you get real joins, GROUP BY, window functions, and CTEs on multi-gigabyte CSVs without installing anything or sending data to a server.

Why DuckDB-WASM changes the game

  • Columnar execution — DuckDB reads only the columns your query touches, so a SELECT on 2 columns of a 200-column CSV is dramatically faster than pandas.read_csv.
  • Vectorized — operates on batches of 1024+ values at a time, using WASM SIMD when available.
  • Direct file registrationduckdb.registerFileHandle streams the CSV from your OPFS/File handle; no full-file copy into memory.
  • Same SQL as server DuckDB — anything you learn transfers to CLI DuckDB, dbt-duckdb, and MotherDuck.

Tutorial: analyze a sales CSV in 30 seconds

  1. Open SQL Playground.
  2. Drop sales_2026.csv — Zro7 auto-registers it as table sales_2026.
  3. Run SELECT country, SUM(amount) AS total FROM sales_2026 GROUP BY country ORDER BY total DESC;.
  4. Add a chart with Local BI Dashboard if you want it visual.

Handy SQL patterns

  • Sample the file: SELECT * FROM sales USING SAMPLE 1%;
  • Cast a text column: SELECT TRY_CAST(amount AS DOUBLE) FROM sales;
  • Time bucketing: SELECT date_trunc('month', ts) AS m, COUNT(*) FROM events GROUP BY m;
  • Window rank: SELECT *, ROW_NUMBER() OVER (PARTITION BY country ORDER BY amount DESC) rn FROM sales;

Zro7 vs cloud SQL playgrounds

Hosted options (BigQuery sandbox, Snowflake trials, Redash) all require uploading your CSV to their infrastructure. That's fine for public data, disastrous for anything with customer PII. DuckDB-WASM gives you the same expressive SQL locally, with no signup, no row limits, and no data leaving your laptop.

Frequently asked questions

How big a CSV can I query?

In practice, up to about 2–4 GB in a browser tab on a 16 GB machine, depending on schema and query. Above that, DuckDB's out-of-core spilling helps but is slower.

Does it support JOINs across two CSVs?

Yes. Drop both files, then join on any column — <code>SELECT * FROM a JOIN b USING (id)</code>.

Can I write back a CSV / Parquet result?

Yes — <code>COPY (SELECT ...) TO 'out.parquet'</code> and Zro7 lets you download the file.

Is the SQL identical to server DuckDB?

Yes. Same parser, same functions, same behavior. Only WASM-specific features (like native extensions) differ.

Any upload?

None. DuckDB-WASM runs entirely in your browser's Web Worker.

Related posts

← Back to blog