How to Set Up DuckDB (Run SQL on a CSV With No Import Step)
By Michael Nocito , data analyst · Published August 8, 2026 By the end of this page you will be running SQL directly against a CSV file on your machine, with no import step, no CREATE TABLE , and no schema written by hand. DuckDB reads the file where it lies, works out the column types itself, and gives you a normal SQL result. It takes one command to install and about a minute to prove. Here is…
DuckDB is a software library that allows running SQL queries directly on a CSV file without the need for any additional import steps. It automatically detects column types and provides a normal SQL result. To get started, install DuckDB using the command `python -m pip install duckdb`. Then, you can query the CSV file by writing a SQL query with the filename in quotes where a table name would typically go.
For example, to select the top 5 countries by revenue from a CSV file named "invoices.csv", use the following command: `SELECT Country, COUNT(*) AS invoices, ROUND(SUM(Total), 2) AS revenue FROM invoices.csv GROUP BY Country ORDER BY revenue DESC LIMIT 5`.
DuckDB infers the column types from the file contents, which can be verified using the `DESCRIBE` command. This feature extends beyond single files and can handle an entire folder of CSV files as one table by using an asterisk (*) in the filename. This eliminates the need for loops or manual concatenation of files. Additionally, DuckDB can interface with pandas, allowing seamless integration with data analysis workflows.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.