> ## Documentation Index
> Fetch the complete documentation index at: https://ngquct-docs-fix-500-query-results.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Import & Export

> Export to CSV, JSON, SQL, MQL, or XLSX. Import SQL, JSON, and CSV files with column mapping and transaction safety

The toolbar's **Export** (`Cmd+Shift+E`) re-reads every table you tick with `SELECT * FROM`, so what is on screen has no bearing on the file: filters, sort, hidden columns, and the page you are on are all ignored, and table size does not matter. **Export Results…** on the grid's right-click menu writes what the tab has loaded instead. Import is `Cmd+Shift+I`.

## Export data

<Steps>
  <Step title="Open the export dialog">
    Open a table or run a query, then click **Export** in the toolbar (`Cmd+Shift+E`), or right-click the results grid and choose **Export Results…**.
  </Step>

  <Step title="Choose a format and scope">
    Pick a format, tick tables in the tree, and set the options for that format.
  </Step>

  <Step title="Export">
    Click **Export**. The destination file appears only on success: a failed or cancelled export removes its partial file.
  </Step>
</Steps>

The last format and its options come back next time, but only after an export succeeds; cancelling discards the changes. **Reset to Defaults** restores the stock settings for the current format.

<Frame caption="Export dialog">
  <img className="block dark:hidden" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/export-dialog.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=c0cf274e0fa37033a21b02a214d5f03d" alt="Export dialog" width="1560" height="960" data-path="images/export-dialog.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/export-dialog-dark.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=727aec19c2b96483891070ee6ab07206" alt="Export dialog" width="1560" height="960" data-path="images/export-dialog-dark.png" />
</Frame>

### What ends up in the file

A whole-table export streams from the database at constant memory, with no row-count limit, and can be cancelled from the progress dialog.

**Export Results…** writes what the tab holds in memory, which is the output of the query that filled it. The filter bar and a sorted header are part of that query, and so is column visibility on a table tab: hiding a column re-queries without it, keeping only the primary key and anything being sorted on. Two things are not part of it. A column value filter narrows the loaded rows in the grid afterwards, so it never reaches the file. And a truncated result with more rows behind it is re-run and streamed in full rather than written as far as it got.

### Formats

<Tabs>
  <Tab title="CSV">
    | Option                                    | Default   |
    | ----------------------------------------- | --------- |
    | Header row                                | Yes       |
    | Delimiter (comma, semicolon, tab, pipe)   | Comma     |
    | Quote handling (always, as needed, never) | As needed |
    | NULL to empty strings                     | Yes       |
    | Line breaks in values to spaces           | No        |
    | Line ending (LF, CRLF, CR)                | LF        |
    | Decimal separator (period, comma)         | Period    |
    | Sanitize formula-like values              | Yes       |

    Sanitizing prefixes a value starting with `=`, `+`, `-`, or `@` with a single quote, so a spreadsheet treats it as text.
  </Tab>

  <Tab title="JSON">
    An array of objects.

    | Option                         | Default |
    | ------------------------------ | ------- |
    | Pretty print                   | Yes     |
    | Include NULL values            | Yes     |
    | Preserve all values as strings | No      |
  </Tab>

  <Tab title="SQL">
    | Option                                           | Default |
    | ------------------------------------------------ | ------- |
    | Compress with gzip (`.sql.gz`)                   | No      |
    | Batch size (rows per INSERT: 1, 100, 500, 1,000) | 500     |

    Structure (CREATE TABLE), Drop (DROP TABLE IF EXISTS), and Data (INSERT statements) are per-table checkboxes, and a multi-table export can mix them.

    <Warning>
      All three are on by default, so an SQL export carries `DROP TABLE IF EXISTS` unless you untick **Drop**. Run that file against the wrong database and it drops the tables first.
    </Warning>

    Not available on MongoDB or Redis.
  </Tab>

  <Tab title="MQL">
    MongoDB only. Writes a `.js` file of `insertMany()` calls that runs in `mongosh`, 500 documents per call by default, with per-collection checkboxes for drop, indexes, and data.

    ```javascript theme={null}
    db.users.insertMany([
      {"_id": {"$oid": "507f1f77bcf86cd799439011"}, "name": "Alice", "age": 30},
      {"_id": {"$oid": "507f1f77bcf86cd799439012"}, "name": "Bob", "age": 25}
    ]);
    ```

    Top-level values keep their type: `ObjectId`, `ISODate`, `BinData` with its real subtype. A typed value nested inside a subdocument or array is written as a string, so re-importing gives you a string where the original held an ObjectId, date, or binary. Export those collections as JSON, or use `mongodump`.
  </Tab>

  <Tab title="XLSX">
    | Option                           | Default |
    | -------------------------------- | ------- |
    | Include headers (bold first row) | Yes     |
    | NULL as empty cells              | Yes     |

    Each table becomes its own worksheet and numbers are stored as numeric cells. A table over 1,048,576 rows, Excel's limit, splits across sheets.
  </Tab>
</Tabs>

## Clipboard paste (CSV/TSV)

Select a row in the data grid and press `Cmd+V` to paste tabular data straight in. Tabs parse as TSV, commas as CSV.

## Import data

**File > Import > Import Data…** (`Cmd+Shift+I`) takes `.sql` and `.sql.gz` files, whose statements execute directly against the database, and `.json`, `.jsonl`, `.ndjson`, `.csv`, and `.tsv` files, which load into a table you pick or one TablePro creates.

<Steps>
  <Step title="Pick the file">
    Choose **File > Import > Import Data…** and select the file. The sheet that opens depends on what you picked.
  </Step>

  <Step title="Set the options">
    Encoding, transaction wrapping, and error handling for SQL; parsing and column mapping for CSV and JSON. TablePro remembers the options from your last successful import, and **Reset to Defaults** restores the stock ones.
  </Step>

  <Step title="Review and import">
    Check the preview, statement count, and file size, then click **Import**.
  </Step>
</Steps>

<Frame caption="Import dialog with SQL file preview">
  <img className="block dark:hidden" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/HJY892UtvXUv1PFn/images/import-dialog.png?fit=max&auto=format&n=HJY892UtvXUv1PFn&q=85&s=689bd3b089c3238ea96355728ae1451a" alt="Import dialog" width="1560" height="960" data-path="images/import-dialog.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/HJY892UtvXUv1PFn/images/import-dialog-dark.png?fit=max&auto=format&n=HJY892UtvXUv1PFn&q=85&s=8534f75186f1f461f68a3ea3ad93ca11" alt="Import dialog" width="1560" height="960" data-path="images/import-dialog-dark.png" />
</Frame>

### Options

| Option                     | What it does                                                             | Default           |
| -------------------------- | ------------------------------------------------------------------------ | ----------------- |
| On error                   | Stop and Rollback, Stop and Commit, or Skip and Continue                 | Stop and Rollback |
| Encoding                   | UTF-8, UTF-16, Latin1, or ASCII                                          | UTF-8             |
| Wrap in transaction        | Runs every statement inside one transaction. Dimmed in Skip and Continue | Yes               |
| Disable foreign key checks | Suspends constraint checks for the import                                | Yes               |

| Mode                  | What happens on a failed statement                                              |
| --------------------- | ------------------------------------------------------------------------------- |
| **Stop and Rollback** | Stops there. With the transaction on, everything rolls back                     |
| **Stop and Commit**   | Stops there, keeping what already succeeded                                     |
| **Skip and Continue** | Logs it and carries on, including a line the parser cannot read. No transaction |

Skip and Continue collects up to 1,000 failures with their line numbers and messages, and the summary counts successes against failures behind a **Copy Details** button. A stop shows the line, the database's own message, and the failing statement, with the dialog still open behind it, ready for a changed setting and another run.

### Disabling foreign key checks

The checkbox runs a different statement per engine, and one of them needs a privilege.

| Engine                                    | Statement                                | Needs                                                         |
| ----------------------------------------- | ---------------------------------------- | ------------------------------------------------------------- |
| PostgreSQL, Redshift, CockroachDB, PGlite | `SET session_replication_role = replica` | Superuser, or `GRANT SET` on the parameter from PostgreSQL 15 |
| MySQL, MariaDB                            | `SET FOREIGN_KEY_CHECKS=0`               | Nothing                                                       |
| SQLite, libSQL, Cloudflare D1             | `PRAGMA foreign_keys = OFF`              | Nothing                                                       |
| Everything else                           | Nothing. The option is ignored           |                                                               |

A server that rejects the statement stops the import with that error, so clear the checkbox and run it again. A dump TablePro exported needs no privilege: it adds foreign keys with `ALTER TABLE … ADD CONSTRAINT` after the data.

### Import JSON

The sheet accepts an array of objects `[{…}, {…}]`, newline-delimited JSON streamed a line at a time, and TablePro's own export shape `{ "table": [ {…} ] }`, so an export round-trips. Then choose a destination:

* **Existing table**: map each JSON field to a column. Fields auto-match by name; switch one off to skip it. A column with no matching field keeps its default or NULL.
* **New table**: name it and review the columns TablePro infers. Name, type, primary key, nullable flag, and default are all editable before the table is created.

Rows insert through parameterized statements, so a JSON value is never concatenated into SQL. Nested objects and arrays are stored as JSON text.

### Import CSV

CSV and TSV open the same sheet as JSON, with parsing options in front of the mapping. The delimiter and encoding are detected from the file; change any option and the mapping re-reads it.

| Option                           | What it does                                           | Default            |
| -------------------------------- | ------------------------------------------------------ | ------------------ |
| Delimiter                        | Comma, semicolon, tab, or pipe                         | Auto-detect        |
| Quote character                  | Double or single quote                                 | Double quote (`"`) |
| Encoding                         | UTF-8, ISO Latin 1, or Windows-1252                    | Auto-detect        |
| First row is a header            | Row 1 becomes the column names; off imports it as data | Yes                |
| Trim leading and trailing spaces | Trims each field before import                         | No                 |
| Treat empty values as NULL       | Inserts NULL instead of empty text                     | Yes                |
| NULL text                        | One more value to import as NULL, `\N` for instance    | None               |

Quoted fields keep embedded commas and newlines (RFC 4180), and a doubled quote (`""`) decodes to one.

### Row imports

CSV and JSON insert in batches, and the on-error and transaction options behave as they do for SQL. They add **Delete existing rows before import**, which clears the target table inside the import transaction, so a failure in the default Stop and Rollback mode brings the rows back. A row where no field matches a mapped column writes nothing and is reported rather than counted.
