What does this generate?
Getting a spreadsheet into a database usually means writing INSERT statements, and writing them by hand is where the mistakes happen: an apostrophe in a surname ends the string early, an empty cell becomes the two-character string '' instead of NULL, and a column named "first name" is not a valid identifier.
This generator reads the CSV, takes the column names from the header row, and writes the statements. Values are escaped by doubling the quote — the form defined by the SQL standard, which every database accepts, unlike backslash escaping that only works in MySQL's default mode.
A <character string literal> that contains a quote symbol represents that symbol by two consecutive quote symbols.
Features
- Standard quote escaping
- A value containing an apostrophe is escaped by doubling it, per the SQL standard. Backslash escaping is a MySQL default, not a portable rule, and it breaks the moment the same script runs against PostgreSQL.
- Empty cells become NULL
- CSV cannot tell an empty string from a missing value. This generator writes NULL, which is what an empty cell almost always means in an export — and it is the one a query for missing data will actually find.
- Identifiers are made safe
- A column called "first name" or "금액 (원)" is not a valid unquoted identifier. Spaces and punctuation become underscores so the statement parses.
- One statement or one per row
- A single multi-row INSERT is far faster, but one bad row rolls the whole thing back. Separate statements are slower and let the rest through. Which is right depends on whether you are seeding or repairing.
- Optional typing
- With typing on, numbers and booleans are written unquoted so they land in numeric and boolean columns. Turn it off when every column is text and you want no surprises.
How to use
- 1
Paste the CSV
Include the header row — the column names come from it.
- 2
Name the table
Type the target table name. Anything that is not identifier-safe is converted.
- 3
Choose the statement shape
One statement for speed when seeding; one per row when a single bad value must not take the rest with it.
- 4
Review before running
Read the output — especially the first and last rows — then run it in a transaction you can roll back.
Frequently asked questions
How are apostrophes in values handled?
By doubling them: O'Hara becomes 'O''Hara'. That is the escape defined by the SQL standard and accepted everywhere. Backslash escaping works only in MySQL's default configuration and fails against PostgreSQL and standard-mode MySQL.
Why are empty cells NULL instead of an empty string?
Because in an export an empty cell almost always means "no value", and NULL is the only thing that a query looking for missing data will find — an empty string is a value, and IS NULL will not match it. If your schema genuinely stores empty strings, turn typing off and edit the output.
Should I use one statement or one per row?
One statement is much faster because the database plans and commits once, which is what you want when seeding a test database. One statement per row is slower but lets the good rows through when one value is malformed — which is what you want when repairing production data.
Does this protect against SQL injection?
It escapes quotes correctly for values you paste yourself, which is enough for a one-off script you read before running. It is not a substitute for parameterised queries in application code — there, the value should never be concatenated into SQL at all.
Which database is the output for?
The syntax used here — INSERT INTO table (columns) VALUES (...) with doubled quotes — is standard SQL and runs on PostgreSQL, MySQL, SQLite, and SQL Server. Type handling for dates and JSON columns varies, so review those before running.
Is my data uploaded?
No. Generation happens in your browser, which matters here because a CSV destined for a database usually holds real records.
Specifications this follows
- PostgreSQL — Lexical Structure: String Constants — The standard doubled-quote escape used in the output, and why backslashes are not portable.
- PostgreSQL — INSERT — Multi-row VALUES syntax and its transactional behaviour.
- RFC 4180 — CSV — How the input is read before the statements are written.
Related tools
- CSV to JSON ConverterTurn a spreadsheet export into a JSON array, with numbers and booleans typed correctly.
- CSV Viewer & ConverterOpen delimited data as a table, guess the delimiter, and convert it to JSON.
- JSON to CSV ConverterTurn a JSON array into a spreadsheet, flattening nested objects and keeping every field.