Skip to content
CleanGlyph home

CSV to SQL Converter & INSERT Generator

Turn CSV with a header row into escaped INSERT statements for PostgreSQL, MySQL/MariaDB or SQLite. Values stay strings unless you opt in. Nothing is executed or uploaded.

Your text never leaves your browser.

0 charactersAnalyzed as you type

SQL output

Paste CSV with a header row, or open a local .csv, .tsv or .txt file, to generate SQL INSERT statements.

SQL options

Letters, digits and underscores. The name is always quoted in the SQL.

Dialect
Delimiter
Statements
Values

Off: empty cells become ''. The text NULL is always a string.

Writes exact numbers like 42 or -3.50 unquoted. 0012, +12 and padded values stay strings.

Summary

Status
—
Data rows
—
Columns
—
INSERT statements
—
Output length
—
Delimiter
—

No data yet: paste CSV with a header row or open a file.

Output length counts UTF-16 code units. The SQL is text only and is never run.

How to convert CSV to SQL INSERT statements

Paste CSV with a header row, open a local .csv, .tsv or .txt file, or load the sample. Enter the target table name and choose PostgreSQL, MySQL/MariaDB or SQLite. The SQL updates as you type. Copy it or download a .sql file, then run it in your own database client against a table that already has matching columns.

Clear removes the CSV and generated SQL while keeping your options. Reset restores the default SQL options while keeping the CSV input.

CSV
id,name,code
1,O'Brien,0012
PostgreSQL
INSERT INTO "my_table" ("id", "name", "code")
VALUES ('1', 'O''Brien', '0012');

PostgreSQL, MySQL and SQLite differences

PostgreSQL and SQLite quote identifiers with double quotes, so a header like order id becomes "order id". MySQL and MariaDB use backticks: `order id`. Text values are single-quoted in all three. For MySQL, backslashes, NUL, line breaks and Ctrl-Z are also backslash-escaped, which assumes UTF-8 and the default SQL mode with NO_BACKSLASH_ESCAPES disabled. PostgreSQL assumes standard_conforming_strings is on; SQLite keeps backslashes literally. Review the script, connection encoding, SQL mode and destination schema before execution. Other configurations require adapting the literals in your database client.

Escaping quotes, apostrophes and SQL injection

Every cell is written as a literal, never as SQL code. Apostrophes are doubled, so O'Brien becomes 'O''Brien', and a cell containing '); DROP TABLE users; -- stays text inside one string under these SQL-mode assumptions. Header names are quoted as identifiers with internal quotes doubled. The table name only accepts letters, digits and underscores, so schema-qualified names like public.users are rejected rather than guessed.

Empty cells, NULL and numbers

By default empty cells become '' and every value is a quoted string, which preserves leading zeros in IDs and postal codes. Turn on Treat empty cells as NULL to write NULL for empty cells. Interpret numeric values writes only exact numbers such as 42, -3.50 or 1e3 unquoted, copied character for character. 0012, +12 and whitespace-padded values stay strings. Destination column types can still coerce strings, round numbers or reject values; this tool does not infer or create a schema.

CSV
id,amount,comment
1,-3.50,
2,0012,ok
Both options on
(1, -3.50, NULL),
(2, '0012', 'ok');

One row per INSERT or batched rows

One row per INSERT makes a failing row easy to find. Up to 100 rows per INSERT writes multi-row VALUES lists, which import faster and produce smaller scripts. Both forms work in PostgreSQL, MySQL/MariaDB and SQLite 3.7.11 and later.

CSV rules and limits

Parsing follows RFC 4180: quoted fields can contain delimiters, doubled quotes and line breaks. Unterminated quotes, stray quotes and rows with the wrong number of fields are errors, and no partial SQL is produced. Completely blank lines are skipped. Headers must be non-empty and unique ignoring case. Limits are 1,000,000 UTF-16 code units of input, 10,000 data rows, 100 columns and 5,000,000 code units of SQL. Files must be UTF-8 and up to 1 MiB.

Need structured data instead of SQL? Use the CSV to JSON Converter or go the other way with JSON to CSV, or inspect JSON with the JSON Formatter. Clean messy exports first with the Text Cleaner or Remove Duplicate Lines, and use the Unicode Inspector to find hidden characters in headers.

Frequently asked questions

Which databases are supported?

PostgreSQL, MySQL/MariaDB and SQLite. The dialect controls identifier quoting (double quotes or backticks) and string escaping. The generated statements are plain INSERT INTO ... VALUES statements; the target table must already exist with matching column names.

How are quotes and apostrophes escaped?

Every text value is written as a single-quoted SQL literal. An apostrophe inside a value is doubled, so O'Brien becomes 'O''Brien'. For MySQL/MariaDB, backslashes, NUL, line breaks and Ctrl-Z are also backslash-escaped for the default SQL mode. Column names are always quoted and any quote character inside them is doubled.

How are empty cells and NULL handled?

By default an empty cell becomes an empty string, ''. Turn on Treat empty cells as NULL to write unquoted NULL instead. Quoted and unquoted empty cells behave the same way. The text NULL in a cell is always written as the string 'NULL', never as a SQL NULL.

Does the first row have to contain column headers?

Yes. The first row is always used as the column list. Header names are kept exactly as written, including spaces, letter case and accented letters, and quoted as SQL identifiers. Empty, duplicate (ignoring case) and control-character headers are rejected with an error instead of being renamed.

Will leading-zero IDs like 0012 be changed?

No. Values stay quoted strings by default. Even with Interpret numeric values on, only exact numbers such as 42, -3.50 or 1e3 are written unquoted; 0012, +12, whitespace-padded numbers and alphanumeric IDs stay strings. Numbers are copied character for character, so large integers and trailing zeros are never rounded.

What file encodings are supported?

Local .csv, .tsv and .txt files up to 1 MiB must be valid UTF-8. A leading UTF-8 byte order mark is removed automatically. Files with invalid UTF-8 bytes are rejected rather than silently altered; re-save them as UTF-8 CSV first.

Is the generated SQL executed?

No. The tool only produces text. Nothing connects to a database and the SQL is never run in your browser. Review the script before running it in your own database client, ideally inside a transaction on a non-production copy first.

Does my data leave the browser?

No. Parsing and SQL generation run locally in your browser. Pasted text, opened files and the generated SQL are not uploaded, logged or stored, and downloads are created locally on your device.