# SQL Dump → CSV

Paste a SQL dump and pull the rows out of its INSERT statements into CSV — one CSV per table, with delimiter, header, NULL and quoting options. Free, private, no upload.

## Run it

- **CLI:** `gizza tool sql-dump-to-csv "INSERT INTO users (id, name) VALUES (1, 'Alice'), (2, 'Bob');"`
- **Web:** https://gizza.ai/tools/sql-dump-to-csv/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/sql-dump-to-csv/tool.json

## Inputs

- `sql` — SQL dump _(field)_
- `table` — Only this table (blank = all) _(field)_
- `delimiter` — Delimiter _(field)_
- `header` — Header row of column names _(field)_
- `null_value` — Text for SQL NULL (blank = empty field) _(field)_
- `quote` — Quoting _(field)_
- `bom` — UTF-8 BOM (for Excel) _(field)_

## Output

- CSV (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `sql` — SQL dump
- `table` — Only this table (blank = all)
- `delimiter` — Delimiter
- `header` — Header row of column names
- `null_value` — Text for SQL NULL (blank = empty field)
- `quote` — Quoting
- `bom` — UTF-8 BOM (for Excel)

Example: `https://gizza.ai/tools/sql-dump-to-csv/?sql=INSERT%20INTO%20users%20%28id%2C%20name%29%20VALUES%20%281%2C%20%27Alice%27%29%2C%20%282%2C%20%27Bob%27%29%3B&table=users&delimiter=comma&header=true&null_value=%5CN&quote=minimal&bom=true`

---

## What this tool does

Paste a SQL dump — a `.sql` file from `mysqldump`, `pg_dump`, SQLite `.dump`, or
any migration/export — and this tool pulls the actual row data out of its
`INSERT` statements and hands it back as CSV. When the dump touches more than one
table, each gets its own labelled CSV section. Everything runs locally in your
browser: nothing is uploaded, it works offline, and there is no sign-up.

## How columns are named

The header row (when enabled) is resolved in this order:

1. **The INSERT column list** — `INSERT INTO users (id, name) VALUES …` → `id,name`.
2. **A matching `CREATE TABLE`** in the same dump, if the INSERT has no column list.
3. **Generated `col1..colN`** as a last resort, when neither is available.

Comments (`-- …`, `# …`, `/* … */`) and every non-INSERT statement are used for
context or skipped. Multiple INSERTs into the same table are concatenated in
order.

## Options

| Option | What it does |
| --- | --- |
| **Only this table** | Export just one table by name (case-insensitive). Leave blank to export them all. Selecting one table also drops the `### TABLE:` section marker, giving you clean single-table CSV. |
| **Delimiter** | `comma` (CSV, default), `tab` (TSV), `semicolon`, or `pipe`. |
| **Header row** | On by default — turn it off to emit rows only. |
| **Text for SQL NULL** | What to write for a `NULL` cell. Empty by default (an empty field); set it to `NULL` or `\N` to make nulls explicit. |
| **Quoting** | `minimal` (default) quotes a field only when it contains the delimiter, a `"`, or a newline; `all` wraps every field in double quotes. |
| **UTF-8 BOM** | Prepend a byte-order mark so Excel opens the file as UTF-8. |

## Example

Input:

```sql
INSERT INTO users (id, name, email) VALUES
  (1, 'Alice', 'alice@example.com'),
  (2, 'Bob', NULL);
```

Output (default settings):

```csv
id,name,email
1,Alice,alice@example.com
2,Bob,
```

With **multiple tables**, each is prefixed with a `### TABLE: <name>` line and
separated by a blank line, so you can split the result or copy one section:

```csv
### TABLE: authors
id,name
1,Ada

### TABLE: books
id,title,author_id
10,On Computation,1
```

## Limits & edge cases

- Values are extracted **verbatim** — numbers, `TRUE`/`FALSE`, and hex/blob
  literals (`0x…`, `X'…'`) are written as they appear; no type conversion.
- String literals honour SQL-standard doubled quotes (`''`) **and** MySQL
  backslash escapes (`\'`, `\n`, `\t`). A PostgreSQL dump that stores a literal
  backslash before a quote is the one ambiguous case.
- Only the `INSERT … VALUES (…)` form carries rows. `INSERT … SET …` and
  `INSERT … SELECT …` have no literal tuples and are skipped.
- Schema-qualified names (`db.users`) are grouped by the final component (`users`).
- Line endings are LF. If a field spans lines it is quoted per RFC 4180.
- Processing is in-memory in your browser; very large dumps (hundreds of MB) may
  be slow or hit the tab's memory limit.

## FAQ

<details>
<summary>Do I need the <code>CREATE TABLE</code> statements too?</summary>

No. If your `INSERT` statements already list their columns
(`INSERT INTO t (a, b) VALUES …`), that is enough for the header row. Including
the `CREATE TABLE` only helps when the INSERTs omit the column list — then the
column names come from the schema instead of generic `col1, col2, …`.

</details>

<details>
<summary>How are multiple tables returned?</summary>

Each table is emitted as its own CSV block, preceded by a `### TABLE: name`
marker and separated by a blank line. To get one table on its own with no
marker, put its name in the **Only this table** box.

</details>

<details>
<summary>How are SQL <code>NULL</code> values handled?</summary>

By default a `NULL` becomes an empty field. If you would rather see it spelled
out — for round-tripping into another database, say — set **Text for SQL NULL**
to `NULL`, `\N`, or whatever your target expects.

</details>

<details>
<summary>Which SQL dialects work?</summary>

The row extractor is dialect-agnostic for the common cases: MySQL/MariaDB,
PostgreSQL, SQLite, and SQL Server dumps all use the same `INSERT INTO … VALUES`
shape. It understands backtick, double-quote, and `[bracket]` quoted identifiers,
`N'…'` national strings, and multi-row VALUES lists.

</details>

<details>
<summary>Is my data uploaded anywhere?</summary>

No. The parsing happens entirely in your browser via WebAssembly. Your dump
never leaves your device, and the page keeps working offline once loaded.

</details>

## Related tools

- [Avro to JSON Converter](https://gizza.ai/tools/avro-to-json/): Decode Apache Avro Object Container Files (.avro / OCF) to JSON, NDJSON, or the embedded schema — no .avsc needed, free and private in your browser.
- [Bencode decoder](https://gizza.ai/tools/bencode-decoder/): Decode bencode (the BitTorrent / .torrent serialization format) into readable JSON, and re-encode JSON back into canonical bencode — in your browser. Nothing is uploaded.
- [Change CSV Delimiter](https://gizza.ai/tools/csv-change-delimiter/): Re-save CSV or delimited data with a different separator (comma, tab, semicolon, pipe) with correct requoting — in your browser. Free, private, no upload.
- [CSV Cleaner](https://gizza.ai/tools/csv-cleaner/): Clean a messy CSV in your browser: trim whitespace, remove duplicate rows, drop empty rows, fill blanks, and normalize delimiters. No upload, free.
- [CSV Dedupe](https://gizza.ai/tools/csv-dedupe/): Remove duplicate rows from a CSV, keeping the first — optionally keyed on chosen columns. Runs in your browser, nothing is uploaded, free.
