Query CSV files with SQL

Drop a CSV file onto DuckLocal and it becomes a table named after the file. DuckDB works out the delimiter, the header and the column types, so you can SELECT, JOIN and GROUP BY straight away. There is no import step and no CREATE TABLE, and files too large for a spreadsheet are still one query away.

Free and open source for macOS, Windows and Linux. No account. No telemetry.

From a CSV file to a result

The file stays where it is. DuckLocal reads it in place.

  1. Drop the file in

    sales.csv becomes a view called sales. Tab-separated .tsv files, .txt files and gzipped .csv.gz files work the same way.

  2. Write SQL against it

    The schema sidebar shows the columns and their inferred types, and autocompletion knows them. Use the full DuckDB SQL dialect: joins, window functions, CTEs and PIVOT.

  3. Keep the answer

    Chart the result, look at each column's distribution, or export the complete result to CSV or Parquet.

Join CSV files like tables

Open orders.csv and customers.csv together and each becomes its own view. Join them in one statement, or join a CSV file with a Parquet file, an Excel sheet or a table in a DuckDB database.

The SQL editor · Results and charts

SELECT c.region,
       count(*) AS orders,
       round(sum(o.amount), 2) AS revenue
FROM orders o
JOIN customers c USING (customer_id)
GROUP BY c.region
ORDER BY revenue DESC;

Many files, and messy ones

Read a whole folder of CSV files as one table with read_csv. union_by_name tolerates files whose columns differ. When one stray text value breaks type detection, read everything as text and cast in SQL.

Reading many CSV files at once

SELECT try_cast(NULLIF(amount, 'NULL') AS DOUBLE) AS amount
FROM read_csv('data/*.csv',
              union_by_name = true,
              all_varchar = true);

Everything around the query

A query box is the start. These are the parts that make it a workspace.

  • .csv .tsv .txtDelimiter, header and types detected by DuckDB
  • .csv.gzGzipped files open as data too
  • data/*.csvOpen every file that matches a pattern
  • folder/Open every data file in a directory
  • OverviewNulls, distinct values, range and distribution per column
  • ChartsBar, line, scatter, pie and map charts from a result
  • Export → ParquetConvert CSV data to Parquet
  • ducklocal queryThe same SQL from a terminal, with JSON output

Your CSV never leaves your computer

Online CSV tools need an upload. DuckLocal is a desktop app with DuckDB embedded: it reads the file from its path, does not copy or change it, and needs no account.

Aggregations run over every row of the file. The grid displays up to 100,000 rows of a result, and an export writes the full result.

  • No upload and no DuckLocal cloud service
  • No database server to install
  • No account and no telemetry
  • The source file is never modified
  • Open source under Apache-2.0

Query CSV from the command line

The same binary runs without a window: ducklocal query --sql "SELECT count(*) FROM 'sales.csv'" prints the result as JSON, for scripts and AI agents.

CSV and SQL questions

Do I need to import a CSV file into a database first?
No. DuckLocal creates a view over the file and DuckDB reads it in place. The file is not copied, converted or changed, and removing the view leaves the file untouched.
Can I join several CSV files in one query?
Yes. Every file you open becomes its own view, so a JOIN between two CSV files is ordinary SQL. You can also join CSV with Parquet, JSON, Excel sheets and DuckDB tables.
Which SQL dialect does DuckLocal use?
DuckDB SQL, which is close to PostgreSQL and adds analytical features such as window functions, PIVOT, and reading files directly with read_csv.
What if a column's type is detected wrongly?
DuckDB infers types from a sample of the file. When a column needs different handling, read it with read_csv(..., all_varchar = true) and convert it with try_cast in your query.
Can I convert a CSV file to Parquet?
Yes. Run SELECT * FROM the view and choose Export → Parquet. The export reruns the query and writes every row.

Run SQL on your own CSV

Download DuckLocal and follow the tutorial with its sample CSV: from file to chart in about ten minutes.