On this page
DUMP
Exports a table, a query result or a Script result to a file or to a table of a local H2 database.
Syntax
DUMP <source> [TO <destination>] [AS <format>] [MODE <mode>] [OPEN]
Quick start
DUMP CUSTOMER;
Writes every row of CUSTOMER to the export folder, in the format of the DefaultFileFormat setting.
DUMP CUSTOMER TO customers AS CSV;
Writes customers.csv to the export folder.
Arguments
| Argument | Required | Values | Default |
|---|---|---|---|
<source> | Yes | A table name, / (the previous result), (<query>), LIB <script>, @<script> or API RESULT. | None |
TO <destination> | No. Required for AS H2. | A file name. <file>.<worksheet> for XLSX and ODS. <connection>.<table> for H2. | Named after the table or the Script; results otherwise |
AS <format> | No | CSV, TEXT, JSON, XLSX, ODS, H2, MD, HTML | The DefaultFileFormat setting |
MODE <mode> | No. XLSX, ODS and H2 only. | OVERWRITE, APPEND. H2 also: APPEND KEY(<column>) [FORCE] and MERGE KEY(<column>[, <column> ...]) | OVERWRITE |
OPEN | No. XLSX and ODS only. | Opens the file after the export | Not opened |
Examples
SELECT * FROM CUSTOMER WHERE COUNTRY = 'FR';
DUMP / TO customers AS TEXT;DUMP (SELECT * FROM CUSTOMER WHERE COUNTRY = 'FR') TO customers.DATA AS XLSX;DUMP LIB monthly.bsql region='EU' TO revenue_eu AS CSV;LET c = 'FR';
DUMP (SELECT * FROM CUSTOMER WHERE COUNTRY = ${c}) TO fr AS CSV;DUMP / TO report.HISTORY AS XLSX MODE APPEND;DUMP CUSTOMER TO WORKCOPY.CUSTOMER AS H2 MODE MERGE KEY(ID);Example session
WORLD> DUMP (SELECT CODE, TRIM(NAME) AS NAME, POPULATION FROM COUNTRY) TO WORKCOPY.COUNTRY_FIGURES AS H2 MODE MERGE KEY(CODE);
MERGE into WORKCOPY.COUNTRY_FIGURES: 254 source row(s), 0 inserted, 1 updated, 253 unchanged.
Completed: 2026-10-18 10:15:47 +02:00 (0:00:00).
WORLD> DUMP CURRENCY TO REPORT AS XLSX;
166 row(s) exported to tab 'DATA' of c:\temp\REPORT.xlsx.
Completed: 2026-10-18 10:05:40 +02:00 (0:00:01).
WORLD> DUMP (SELECT TRIM(CONTINENT) AS CONTINENT, COUNT(*) AS COUNTRIES FROM COUNTRY GROUP BY CONTINENT) TO REPORT.BY_CONTINENT AS XLSX;
7 row(s) exported to tab 'BY_CONTINENT' of c:\temp\REPORT.xlsx.
Completed: 2026-10-18 10:05:45 +02:00 (0:00:00).
SELECT CODE, TRIM(NAME) AS NAME FROM COUNTRY WHERE REGION = 'Baltic Countries' ORDER BY CODE;
DUMP / TO baltic AS MD;
| CODE | NAME |
| --- | --- |
| EST | Estonia |
| LTU | Lithuania |
| LVA | Latvia |
Details
PULL is a compatibility alias of DUMP. DUMP writes data or results to a file or to a table of a local H2 database; it is not a database backup.
Sources
CUSTOMER, or"Sales Data"for a name with spaces or other special characters: every row of the table or view, found asDESCRfinds it./: the previous result, exactly as it was displayed. The query is not run again. A result whose display stopped at theMaxRowsOnScreenlimit is refused: export it withDUMP (<query>), which runs the query and exports every row.(<query>): the query, run now. Its${name}variables are passed to the database as typed values. Only the query in parentheses is read for variables:TO,ASand the rest of the command are taken as written.LIB <script> [name=value ...]or@<script>: the final tabular result of a Scripts Library Script, run asLIB RUNruns it, with the same named arguments, without displaying its results. The result is written only when the Script ends with the statusSUCCESS, and only when it produces a tabular result; aLETquery of the Script is never the exported result.API RESULT: the result of the lastRUN.
Formats and files
CSV: comma or semicolon separated (theCsvSeparatorsetting), standard quoting.TEXT: UTF-8, tab separated.TXTis accepted asTEXT.JSON: an array of objects.XLSXandODS: the worksheetDATA, or the worksheet named after the file (TO report.MONTHLY). The other worksheets of an existing file are kept, and aQUERIESworksheet records the source of each worksheet.H2: a table of a local H2 database,TO <connection>.<table>. A connection that does not exist yet is created in the export folder.MDandHTML: a table.
Without AS, the DefaultFileFormat setting applies. Files are written to the export folder (DefaultFolder). Without TO, the file is named after the table, after the Script, or after DefaultExtFileName (results) for /, a query and API RESULT.
Write modes
MODE OVERWRITE, the default: replaces the table or the worksheet.MODE APPEND(H2,XLSX,ODS): adds the rows of the result to the existing table or worksheet when it has the same number of columns, with the same names, in the same order as the result (names compared without regard to case). The data types are not compared and the query is not examined, so any query can be appended. A destination that does not exist yet is created. When the columns differ, nothing is written and the error names the difference.NULLvalues are appended asNULL(an empty cell in a worksheet).MODE APPEND KEY(<column>) [FORCE](H2): adds only the rows whose key is greater than the table's current maximum, seePULL.MODE MERGE KEY(<column>[, <column> ...])(H2): the rows whose key is not in the table are inserted, the rows whose key is there and whose other columns differ are updated, and the others are only counted. A row of the table whose key is not in the result is kept as it is: MERGE never deletes. The summary gives the counts, for exampleMERGE into WORKCOPY.CUSTOMER: 10000 source row(s), 120 inserted, 37 updated, 9843 unchanged.
MERGE in detail
- The whole result is read every time: without change tracking in the source, every row must be compared. Only new and changed rows are written.
- The key is one or more columns of the result, named in
KEY(...)without regard to case. An existing table must have the same columns, with the same names, in the same order as the result. - The values are compared after conversion to the table's column types: a
DECIMAL(10,2)column rounds3.004to3.00, so that value is unchanged; text is compared exactly, letter case and trailing spaces included. A change from or toNULLis an update. - Nothing is written, and the error says why, when a key column is not in the result, when a key value is
NULL, when a key appears twice in the result or already twice in the table, when a value cannot be converted to the column's type, or when the columns differ. - The changes are made in one transaction: after a failure or a CTRL+C, the table is unchanged. A table that does not exist yet is created with a unique index on the key; if the MERGE then fails, the empty table is removed.
- The rows are first copied into a temporary table of the destination database: its file grows by about the size of the result, and H2 reuses that space afterwards. A table with an index on the key columns is merged faster.
Large exports
- An
XLSXexport to a new file, a new worksheet or withMODE OVERWRITEstreams its rows: the memory it needs does not grow with the number of rows. The rows wait in compressed temporary files in a folder of the system temporary folder, deleted at the end of the export. A worksheet holds at most 1048575 rows. MODE APPENDto an existingXLSXworksheet, and the other worksheets of an existing file, are held in memory.ODSfiles are built in memory and are much slower thanXLSXandCSVfor large results.- An export that runs longer than 10 seconds prints its progress every 10 seconds, for example
DUMP in progress: 120000 row(s) so far (0:00:20).OUTPUT QUIEThides these lines in a Script. - From PostgreSQL, the rows are read in batches when
Autocommitis off. With auto-commit on, the PostgreSQL driver reads the whole result into memory first.
Completion, cancellation and failures
- After the success message, a second line gives the date and time the export finished, in local time with its UTC offset, and how long it took:
Completed: 2026-10-14 19:25:43 +02:00 (0:01:12). - CTRL+C cancels the export: the source query is cancelled where the database driver supports it, and the writing stops between two rows. A message says what was left behind. A file is written to a temporary file and replaces the destination only at the end, so it is never left half written and an existing file stays as it was. An
H2destination receives no row; withMODE OVERWRITEthe table may already have been recreated empty, because H2 commitsDROP TABLEandCREATE TABLEat once. On PostgreSQL withAutocommitoff, a cancelled query aborts the current transaction: runROLLBACKbefore the next statement. - A file that another program holds open (Excel, on Windows) cannot be replaced: the export fails and the file is unchanged. When BroadSQL runs out of memory, the export fails with a message that says what was left behind, as after CTRL+C.
A table name alone
DUMP <table> alone, with no other word, keeps its original file naming and format choice: the file is named after the table (the worksheet too) and its format is DefaultFileFormat, or tab separated text beyond MaxRowXLSX rows. It is written by the same writers as every other form, so a CSV file uses the CsvSeparator setting.
Time zones
Time-zone-aware timestamps are exported the same way on every computer: the text formats keep each value's own offset (2024-01-15 10:00:00+05:00), XLSX and ODS hold a native date and time cell of the same moment in UTC, and H2 keeps the offset. Dates, times and timestamps without a time zone are never converted.
Protected destinations
The Connections Definition File ($CDF) is a protected BroadSQL system database: AS H2 refuses it as a destination, and so does any other connection that opens the same database file. Nothing is written.
Related
- PULL, the compatibility alias of DUMP
- LOAD, the import command
- Export guide
- Exporting a Script's result
Used in these how-tos
- How do I find orphan rows, duplicates and missing values?
- How do I check a colleague's spreadsheet list against the database?
- How do I find the rows that differ between two databases?
- How do I export tables and query results with DUMP? A step-by-step tutorial
- How do I build a weekly Excel report with one tab per query and a tab that grows?
- How do I keep a local copy of a production table up to date?
- How do I save a query with parameters and run it by name?
- How do I write a report Script that stops at the first failure?
- How do I investigate a support ticket and keep the evidence?
- How do I verify that a data fix changed only the intended rows?
- Largest countries of a continent Scripts Gallery
- Estimated row count of every table (PostgreSQL) Scripts Gallery
- Duplicate values in a column (template, runs on WORLD) Scripts Gallery
- Rows missing between two databases (template, WORLD and WORLD-QA) Scripts Gallery
Last modified in release 5.5.0.
Found something wrong or unclear on this page? Tell us, with the page address.