Developer Data

SQL to CSV

Processed in your browser · nothing is uploaded

Local · reads INSERT, not arbitrary SQL
Advertisement
320 × 100

Reads INSERT statements back into CSV: column names from the statement, values un-escaped, and NULL turned back into an empty field. Both one-statement-per-row and batched forms are handled.

How to use the sql to csv

1 Paste your input. The result appears immediately.
2 Adjust the indent if the default is not yours.
3 Copy the result, or save it as a file.

This is the reverse of an export, and it comes up more than you would expect: a dump file, a migration someone wrote by hand, a set of statements pasted into a ticket. Getting them into a spreadsheet means parsing the tuples, and the tuples contain commas inside quoted values, which is exactly the case a split on commas gets wrong.

What it does not do is parse SQL properly. It looks for INSERT INTO table (columns) VALUES and reads the tuples after it, which covers what generators emit and what people write by hand. A statement with an expression in it. VALUES (1, NOW()): comes through as the literal text NOW(), because evaluating it would need a database. Anything more complicated needs a real parser, and the page says so rather than producing plausible nonsense.

The columns come from the first statement. If a dump has statements with different column lists, only the first is used as the header, and that is worth checking before trusting the result.

Questions

Yes; one statement with many value tuples, and one statement per row, both work.

RFC 4180, the CSV format
Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding