Convert a CSV to SQL INSERT statements
A CSV in, a .sql script any database will run.
- PostgreSQL, MySQL, SQLite
- Column types detected
- Quotes escaped correctly
- Nothing uploaded
1.Open the file
CSV or TSV. Drag it here, or choose a file.
Why it exists
Database import wizards are fussy about CSVs, and command-line loaders need file access the database server often does not have. A plain .sql script works everywhere a query does. Generating it by hand, though, is where quoting goes wrong: one apostrophe in a surname breaks the whole script, and one unescaped backslash corrupts a row in MySQL. This writes the script with the escaping each database actually needs.
What it does
- Writes a CREATE TABLE statement with a type for each column, decided from every value in it.
- Writes the rows as multi-row INSERT statements, in batches of a size you choose.
- Quotes names and escapes values for the database you pick, including MySQL's backslashes.
- Writes empty cells as NULL, and keeps columns with leading zeros or very long numbers as text.
- Can wrap everything in a transaction, so a failure part-way leaves the database as it was.
Why batches
One INSERT per row is slow to run, and one INSERT for a million rows is too large for most servers to accept. A few hundred rows per statement is fast and stays under the usual packet and statement-size limits; lower it if your server complains.
Questions
- Which databases does it support?
- PostgreSQL, MySQL and MariaDB, and SQLite. The scripts are plain SQL, so other databases that follow the standard, such as SQL Server for the INSERT statements, usually accept them with small changes to the CREATE TABLE.
- How are the column types chosen?
- From every value in the column. A column of whole numbers becomes BIGINT, decimals become a floating-point type, true/false becomes BOOLEAN, ISO dates become DATE, and anything else, including numbers with leading zeros, becomes TEXT. You can edit the CREATE TABLE in the script before running it.
- Is it safe to run on a production database?
- The script only creates one table and inserts into it. Read it first, as you would any script: the preview shows the start of it, and the table name is yours to choose.
The longer answer
This page does the job. The guide explains it — including the parts a tool cannot decide for you.
How to run SQL queries on a CSV file without a database (2026 guide)You do not need Postgres to run a GROUP BY. Here is how to query a CSV in place with DuckDB, SQLite, q or your phone, and which one fits which situation.The other tools
- Open a CSV file in your browserDrop a file in. It opens here, and it stays here.Open it
- Run SQL on a CSV fileReal SQL, on your file, without installing a database.Open it
- Merge CSV files into oneSeveral files in, one file out, columns matched by name.Open it
- Remove duplicate rows from a CSVDuplicates on the columns you say identify a row.Open it
- Compare two CSV filesAdded, removed, changed, matched on a key rather than line by line.Open it
- Convert a CSV to PDFA CSV, laid out as a readable table, saved as a PDF.Open it
- Convert a CSV to ExcelA real .xlsx, with nothing in it changed on the way.Open it
- Convert a CSV to JSONEvery row an object, every header a key.Open it
- Convert JSON to CSVA tree, flattened into a table you can open anywhere.Open it
- Convert Excel to CSVEvery sheet of a workbook, out as clean UTF-8 CSV.Open it
- Split a CSV fileOne file too big to use, as several that are not.Open it
- Clean up a messy CSVGermany, germany and “Germany ” become one value again.Open it