Staaarter

SQL INSERT to CSV Converter

Extracts the column list and literal values from one or more simple INSERT INTO <table> (<cols>) VALUES (...) statements and converts them into CSV rows. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-29
By Staaarter Team
conversiondatabasesql

Overview

Introduction

A database dump or migration script often lands as a pile of INSERT statements rather than a clean data file. This tool pulls the column names and literal values back out of simple INSERT statements into CSV.

It's intentionally scoped to straightforward, single-table INSERT ... VALUES statements rather than trying to be a general SQL parser, and it says so clearly when something falls outside that scope.

What Is SQL INSERT to CSV Converter?

A SQL-to-CSV converter that locates every `INSERT INTO <table> (<cols>) VALUES (...)` statement in the input, and turns the column list into a CSV header and each VALUES tuple into a CSV data row.

It supports both several separate INSERT statements and a single INSERT with multiple comma-separated VALUES tuples.

How SQL INSERT to CSV Converter Works

The input is scanned for every `INSERT INTO` occurrence; each statement's column list (between the parentheses right after the table name) becomes the CSV header, taken from the first matching statement.

The VALUES clause is then walked character by character, tracking quote and parenthesis state so commas and parentheses inside a quoted string literal don't confuse the tuple boundaries; each literal token is converted to a CSV cell (quoted strings are unquoted and unescaped, NULL becomes empty, numbers pass through as-is).

When To Use SQL INSERT to CSV Converter

Use it when you have a SQL dump, migration script, or seed file full of simple INSERT statements and need the data back out as CSV for a spreadsheet or another tool.

It's also useful for quickly inspecting what data a set of INSERT statements actually contains without running them against a real database.

Features

Advantages

  • Handles multiple INSERT statements, or one statement with several VALUES tuples, in a single pass.
  • Correctly unescapes quoted string literals and doubled quotes back into plain CSV text.
  • Gives a clear, explicit error when no matching INSERT statement is found, instead of silently returning nothing.

Limitations

  • Not a full SQL parser: subqueries, function calls (like NOW() or CONCAT(...)), expressions, and multi-table statements aren't supported and may produce incorrect results.
  • An unquoted, unbalanced parenthesis inside a value can confuse the tuple boundary detection, since it's tracked by nesting depth rather than a full grammar.

Examples

Converting INSERT statements back to CSV

Input

INSERT INTO users (id, name, email) VALUES (1, 'Ada Lovelace', '[email protected]');
INSERT INTO users (id, name, email) VALUES (2, 'Alan Turing', NULL);

Output

id,name,email
1,Ada Lovelace,[email protected]
2,Alan Turing,

The column list from the first statement becomes the header; NULL in the second row becomes an empty cell.

Best Practices & Notes

Best Practices

  • Stick to simple literal VALUES (quoted strings, numbers, NULL); rewrite anything using functions or subqueries into a literal value first.
  • If you get a "no INSERT statements found" error, double check the input actually has an `INSERT INTO ... VALUES (...)` shape rather than, say, UPDATE or a bare VALUES clause.
  • Use CSV to SQL Converter afterward to confirm a round trip reproduces equivalent INSERT statements.

Developer Notes

Tuple extraction tracks parenthesis depth and quote state together, character by character, rather than using a single regex for the whole VALUES clause, because a naive regex can't reliably tell a tuple-closing `)` apart from a `)` that happens to appear inside a quoted string literal.

SQL INSERT to CSV Converter Use Cases

  • Extracting tabular data out of a SQL dump or migration script for use in a spreadsheet
  • Auditing what data a seed file's INSERT statements actually contain
  • Converting database export scripts into CSV for import into a different system

Common Mistakes

  • Feeding it SQL with function calls or expressions in the VALUES list (like `NOW()` or `price * 1.1`) and expecting them to resolve; only literal values are supported.
  • Assuming every dialect's identifier quoting (backticks, brackets, double quotes) is handled identically; simple cases work, but exotic quoting may not be recognized.

Tips

  • If parsing fails, check for a stray, unquoted parenthesis inside one of the values, a common cause of misdetected tuple boundaries.
  • Pair with CSV to SQL Converter to confirm the extracted data round-trips into equivalent INSERT statements.

References

Frequently Asked Questions