Export SQL query results to Excel or CSV from the command line

Getting query results into Excel usually means a GUI, some copy-pasting, or a different one-off script for every output format.

The problem: one tool per format, repeated by hand

A recurring report rarely stays in one format. Today it's a spreadsheet for finance, tomorrow a CSV for another system to pick up, next week someone asks for the same numbers as a table they can paste into a wiki page. Each format usually means a different export path, a different tool, or a script someone wrote once and now maintains by hand.

The BroadSQL approach: one syntax, every destination

PULL copies a query's results into a local H2 table, a tab of an Excel or OpenDocument spreadsheet, or a flat CSV, JSON, Markdown, or HTML file: the destination format is just the last word of the command:

PULL orders TO snapshot.orders AS H2;
PULL (SELECT * FROM orders WHERE status = 'PENDING') TO report.pending_orders AS XLSX;
PULL (SELECT * FROM orders WHERE status = 'PENDING') TO pending_orders AS CSV;

The first line copies a table straight into a local H2 database for further work. The second writes a filtered query into a tab of report.xlsx, leaving any other tabs in that file untouched. The third writes the same query as a plain CSV file. EXPORT and DUMP (BroadSQL's older export commands, for a whole table or a toggled "send everything to this file" mode) remain fully supported for XLSX, ODS, CSV, plain text, and legacy MS Access output, if that's the workflow you already have.

Honest scope

This is export, not a reporting or BI tool. There's no dashboarding, no scheduling built into BroadSQL itself, no chart output. What it does replace is the manual step of getting a result set out of the database and into the format someone downstream actually needs, repeatably and without a GUI.

Who this is for

Data stewards, analysts, and anyone who produces the same report, in the same format, on a schedule someone else set.

Get recurring reports off your plate

I set up recurring export scripts (one file, one command) run on a schedule your OS already provides (cron, Task Scheduler), so a report that used to take someone fifteen minutes of manual work every week just runs. Get in touch to talk about automating your report.