Skip to content

querybara export

  • CLI
  • PostgreSQL
  • MySQL
  • MariaDB

querybara export writes tables, or the result of a query, to a file. Rows stream from a server-side cursor to the file page by page, so memory stays flat however large the table is. Several tables go to one file each, into one ZIP archive, or into a single combined file.

querybara export --help
Usage: querybara export [options] <target>
export tables or a query result to CSV, TSV, JSON, JSON Lines, Excel, XML,
Parquet, SQL, HTML or Markdown
Arguments:
target profile name or id, or connection URI
Options:
--table <name> table to export (schema.table on PostgreSQL);
repeatable
--query <sql> export the result of this query instead
--format <format> output format (choices: "csv", "tsv", "json",
"jsonl", "xlsx", "xml", "parquet", "sql", "sql-ddl",
"html", "markdown")
--out <path> file to write ("-" for stdout); a folder for several
tables without --one-file
--gzip compress the output with gzip
--zip a file per table inside one ZIP archive (--out is
the .zip file)
--one-file several tables into one file (all formats but csv,
tsv, jsonl and parquet)
--no-header CSV, TSV and Excel: no header row
--delimiter <char> CSV delimiter (default ,)
--null <text> CSV and TSV: text written for NULL (default: an
empty field)
--pretty JSON: indent each object
--rows-per-insert <n> SQL: rows per INSERT statement (default 100)
--drop-table sql-ddl: DROP TABLE IF EXISTS before each CREATE
TABLE
--decimals <as> xlsx: decimals as exact text, or as numbers where a
double holds them exactly (choices: "text",
"number")
--codec <codec> parquet: page compression (default snappy) (choices:
"snappy", "zstd", "gzip", "none")
--bom start with a UTF-8 byte order mark (for Excel)
--database <name> database to connect to
-y, --yes run a --query that needs confirmation (as query
would ask) without asking
--tls <mode> TLS mode for this run: disable, require, verify-ca
or verify-full
--ssh <user@host[:port]> reach URI targets through this SSH server; repeat
for jump hosts, in order
--ssh-key <path> SSH private key file (OpenSSH, PEM or PuTTY .ppk)
--ssh-password-env <VAR> take the SSH password from this variable (default
QUERYBARA_SSH_PASSWORD, else a prompt)
--ssh-agent log in with the keys of ssh-agent (SSH_AUTH_SOCK) or
Pageant
--proxy <url> reach URI targets (or their first SSH server)
through socks5://host:port or http://host:port
--ssh-accept-new trust and remember an SSH host key not seen before
(a changed key is always refused)
--known-hosts <path> SSH known hosts file (default: the desktop app's)
-h, --help show help for a command
Rows stream from a server-side cursor to the file page by page, so memory stays flat. JSON
keeps bigints and decimals exact and embeds JSON columns; SQL writes multi-row INSERTs (with
the CREATE TABLE, indexes and foreign keys for sql-ddl). Excel writes typed cells (dates as
Excel dates; bigints and decimals as text unless --decimals number); XML writes <export>,
<table name="…"> and a <row> per row; Parquet typed columns (exact decimals, dates, timestamps,
UUIDs) in row groups; HTML a self-contained page; Markdown pipe tables.
Several tables go to <out>/<table> files, into one ZIP archive with --zip, or with --one-file
into one file (a SQL file with foreign keys last, a JSON object keyed by table name, a
worksheet or section per table). A failed or cancelled export removes the partial file.
Examples:
querybara export prod --table public.orders --format csv --out orders.csv
querybara export prod --table orders --table items --format sql-ddl --one-file --out shop.sql --gzip
querybara export prod --table orders --table items --format jsonl --out exports/
querybara export prod --table orders --table items --format xlsx --one-file --out shop.xlsx
querybara export prod --table orders --table items --format csv --zip --out shop.zip
querybara export prod --table events --format parquet --codec zstd --out events.parquet
querybara export dev --query "select id, email from users where active" --format json --out - | jq .

The --tls and SSH options are described in Global options.

One table to CSV:

Terminal window
querybara export shop-prod --table shop.orders --format csv --out orders.csv

Two tables with their DDL into one gzipped SQL file:

Terminal window
querybara export shop-prod --table shop.orders --table shop.order_items --format sql-ddl --one-file --out shop.sql.gz --gzip

One Excel workbook with a worksheet per table:

Terminal window
querybara export shop-prod --table shop.orders --table shop.order_items --format xlsx --one-file --out shop.xlsx

One table to Parquet, with ZSTD-compressed pages:

Terminal window
querybara export shop-prod --table shop.order_items --format parquet --codec zstd --out order_items.parquet

A file per table, in a folder or in a ZIP archive:

Terminal window
querybara export shop-prod --table shop.orders --table shop.order_items --format jsonl --out exports/
querybara export shop-prod --table shop.orders --table shop.order_items --format csv --zip --out shop.zip

A query result to stdout:

Terminal window
querybara export shop-dev --query "select id, email from shop.customers where active" --format json --out - | jq .
--format What it writes
csv CSV; --delimiter, --null, --no-header
tsv TSV; --null, --no-header
json JSON; bigints and decimals stay exact, JSON columns are embedded; --pretty
jsonl One JSON object per line
xlsx Excel with typed cells and real dates; bigints and decimals as text unless --decimals number; --no-header
xml <export>, a <table name="…"> per table and a <row> per row
parquet Typed columns in row groups: exact decimals, dates, timestamps and UUIDs; --codec
sql Multi-row INSERT statements; --rows-per-insert
sql-ddl The CREATE TABLE, indexes and foreign keys with the INSERTs; --drop-table
html A self-contained page
markdown Pipe tables

--one-file combines several tables into one file for every format but csv, tsv, jsonl and parquet: a SQL file with the foreign keys last, a JSON object keyed by table name, or a worksheet or section per table. --gzip compresses the output. --bom starts the file with a UTF-8 byte order mark, for Excel.

A failed or cancelled export removes the partial file.

A Parquet file holds one table. Several tables go to one file each, in a folder or a ZIP archive with --zip.

  • --codec sets the page compression: snappy (the default), zstd, gzip or none. ZSTD needs Node.js 22.15 or later.
  • Parquet compresses its own pages, so --gzip is refused with --format parquet.
  • A Parquet file, like an Excel workbook, is written to a file: --out - is refused.
  • --codec works only with --format parquet.

Integers, numeric(p,s) decimals, dates, timestamps (UTC-adjusted for timestamptz), UUIDs and JSON are written as the matching Parquet types. Other values, such as unbounded numeric, intervals and arrays, are written as text, as the server sent them. A value the column type cannot hold, such as PostgreSQL’s infinity date, fails the export and names the column and the row.

Exporting tables only reads them. A --query goes through the same checks as querybara query: a statement that needs confirmation asks, or needs --yes.

Documents Querybara 0.1.1 · built frombc9f5aa