Help › Run queries

Run SQL from the command line

List your saved connections, run SQL on them, and run notebooks from a terminal, a script or a scheduled job with the querlyn command, with Querlyn's passwords and safety checks.

Querlyn 0.1.0 is not released yet. This help describes it ahead of release.

The querlyn command runs SQL on a connection you saved in Querlyn and writes the rows to the terminal, a file or another program. It connects exactly as Querlyn does: the same SSH routes and tunnels, the password from your keychain or password manager, cloud sign-in, and the same safety checks. It reads Querlyn's connections and settings, records each run in the query history, and changes nothing else: no saved password, no host key.

Install the command

The querlyn command comes with Querlyn, inside the application. To run it from any terminal window, choose Querlyn › Install Command Line Tool, or use this link: Querlyn › Install Command Line Tool. Querlyn puts a link named querlyn in /usr/local/bin, a folder every shell looks in. When that folder needs an administrator, or does not exist yet, macOS asks for an administrator's name and password first. Then open a new terminal window and run querlyn --help.

If another program named querlyn is already in that folder, Querlyn asks before replacing it. Command Palette › Querlyn: Uninstall Command Line Tool removes the link again; it never removes a querlyn that is not Querlyn's.

The link points into the copy of Querlyn it was installed from. Updates keep it working; after moving Querlyn to another folder, install the command again.

List your connections

querlyn connections list

The list has each connection's name, engine, environment, folder and ID. Host names, users and passwords are never shown. Add --format json (or csv, ndjson) for a script to read.

Run a query

querlyn query --connection "Orders (prod)" --sql "SELECT id, total FROM orders WHERE created_at > now() - interval '1 day'"

Name the connection as it is in the sidebar; any mix of capitals works. When two connections have the same name, use the ID from the list. Give the SQL with --sql, or from a file with --file report.sql (--file - reads it from standard input). Add --database to run in another database of the same server.

A script runs statement by statement on one session, as running a selection does in a query tab, and stops at the first error: nothing after it runs.

On a MongoDB connection, write the statements as in its query tabs, in MongoDB's shell syntax:

querlyn query --connection Events --sql 'db.events.find({ level: "error" }).limit(20)' --format ndjson

On a Cassandra connection, write CQL, as in its query tabs; cqlsh's CONSISTENCY works too:

querlyn query --connection Metrics --sql "CONSISTENCY ONE; SELECT * FROM readings WHERE device = 7f3e2a10-4c1b-4d2e-9a8f-0b6c5d4e3f21 AND day = '2026-10-08'"

On a Kafka connection, --sql takes Kafka's commands (consume, produce, describe; see Use Kafka commands in a query tab). A produce on a Production connection needs --yes, as any statement Querlyn would ask about does.

Formats and files

OptionWhat is written
--format tableAligned columns for reading, with the row count (the default). Long values end with an ellipsis.
--format csvComma-separated values with a header row, as an export writes them. NULL is an empty field; empty text is "".
--format jsonAn array of objects per result. Decimals keep every digit, dates and times are ISO 8601, NULL is null.
--format ndjsonOne JSON object per row, on its own line.

Rows are written as they arrive, so a result of any size streams through without filling memory. A script with several queries writes each result in turn: CSV results are separated by a blank line, each with its header, and JSON results follow each other as separate arrays.

With --output rows.csv the rows go to a file instead. The file appears only when the run ends without an error; a failed run leaves no half file.

Messages from the server, and what statements without rows did (UPDATE 3), go to standard error in the CSV and JSON formats, so standard output holds only rows.

Run a notebook

querlyn notebook run runs every cell of a notebook, in order, as Notebook › Run All Cells does in Querlyn, and writes the notebook with its new results:

querlyn notebook run reports/monthly.ipynb --param region=EU \
  --param period=2026-09-01..2026-09-30
  • Its connections are found as Querlyn finds them when you open the notebook: by the connection the file names, exactly. A connection this computer does not have is an error, never made; --connection <name> chooses one for the notebook's own.
  • Its cells run as in Querlyn: one session per connection, so a temporary table one cell makes is there for the next; scratch cells, results by name, Python cells in a kernel found as Querlyn finds one. A cell that fails stops the run, and the cells after it do not run. A cell whose server lacks what it needs (a runbook's) is skipped, as in Querlyn, and the run goes on.
  • Its parameters take the values --param name=value gives, for this run only, as Notebook › Run with Values… does: numbers as written, dates as 2026-01-31, a date range as start..end, true or false. A name the notebook has no parameter of is an error.
  • The result is written beside the notebook as <name>.run.ipynb (replaced each run), or where --output <file.ipynb> says. The notebook itself is never written, unless you give --in-place. It is written after a cell fails too, with the error in that cell.

Before anything runs:

  • Production: a cell that Querlyn cannot prove only reads (a write, or a statement it cannot classify) does not run on a Production connection, and neither does anything else, unless --confirm-production <name> names that connection. Its question is then confirmed, with Touch ID where it is turned on. --yes is not enough.
  • Other connections: a statement Querlyn would ask about runs with --yes, as with querlyn query.
  • A read-only connection refuses a cell that may write.
  • Python in a notebook you have not trusted on this computer (see Open notebooks from others) runs only with --trust: its code runs with your permissions. Without a Python kernel on this computer, a notebook with Python cells does not run.

Each cell's ending is printed as it is in the notebook: how many rows, or why it failed, or that it did not run, or why it was skipped. A skipped cell is not a failure.

From the second run on, each cell also says what changed since the run before, compared with the results the last run wrote to the same output file. --report <file> writes a report of the run, and --report-dashboard lays it out as the notebook's dashboard.

--deliver and --deliver-result send the run's report or a result to a destination saved in Querlyn (Slack, email, a Google Sheet): see Send a notebook's results.

To have your computer run a notebook at set times, use Notebook › Schedule… in Querlyn: it writes this command for your computer's scheduler, with --schedule and the schedule's ID, so that the run is checked against its schedule and its ending is shown in Scheduled Runs. See Run a notebook on a schedule.

Query history

Each run, a notebook's included, is recorded in the query history as a run in a query tab is, by the connection's Query history setting: on a Production connection, by default, when it ran and how it ended but not the SQL. Its entry says Command line. Querlyn can be open meanwhile: its history panel shows the new entries when you come back to its window.

Allow a connection from the command line

Any program running as you could run querlyn to use your saved passwords, so each connection says whether the command line may use it on this computer. In Querlyn, choose Query › Edit Connection… and turn Allow from the command line on or off. It is off for Production connections and on for the others until you change it, and it is kept on this computer only: it is not synced and not shared with a team.

A connection that is not allowed is refused before anything is read from the keychain or sent, and the command ends with code 6. The same goes for querlyn commands that run a notebook on a connection.

Safety

The command line follows your confirmation settings, the connection's environment and its read-only switch, before anything runs:

  • A statement Querlyn would ask about (a DELETE without WHERE on Production, for example) is refused, and nothing in the script runs. Add --yes to run it.
  • With Touch ID turned on for the connection's risk level, --yes also asks for Touch ID. Where Touch ID can't be asked, --yes alone confirms, and the command says so.
  • A read-only connection refuses SQL that may write.
  • A connection a team shared asks about destructive and unrecognised statements, whatever your own settings say.
  • Masked columns are written as •••••••• wherever Querlyn would mask them. When the command line can't tell which column a value comes from, it masks it too.

Warning: A connection that commits by hand (the default on Production) keeps a script's changes only if the script ends with COMMIT. Without it the changes are rolled back when the command ends, and the command says so and ends with code 1.

To stop a running query, press ⌃ on macOS or Ctrl on Windows and Linux and C: the statement is cancelled on the server. Pressing it again ends the command at once.

What it can't do yet

  • A connection that asks for its password each time, or an SSH server whose host key you haven't trusted yet, can't be used: connect once in Querlyn (and keep the password in the keychain or a password manager).
  • Query parameters (:name, $1) are not asked for: the statement is sent as written.

The first time the command reads a password from the macOS keychain, macOS asks whether querlyn may use it. Choose Always Allow to not be asked again.

Exit codes

CodeMeaning
0Everything ran.
1A statement failed (nothing after it ran), or the script left a transaction open, which was rolled back.
2The command could not be understood.
3The connection could not be found or opened, or needs an answer the command line can't give; for a notebook, also: it has Python cells and no Python kernel was found.
4Refused before anything ran: a confirmation was not given, or a read-only connection would have been changed; for a notebook, also: Production without --confirm-production, or Python in a notebook not trusted here without --trust.
5A file could not be read or written, or Querlyn's settings or saved connections could not be read.
6The connection is not allowed from the command line on this computer (see Allow a connection from the command line).
7A notebook's run ended, and a delivery of it failed. A cell that failed (1) comes first.
130Interrupted: the running statement was cancelled.
141The output was closed early (as by head): the rest did not run.

For a notebook, 1 means a cell failed (the cells after it did not run), or the run left a transaction open, which was rolled back, and 2 also means a --param names no parameter of the notebook or is not a value of its type.

querlyn help query and querlyn help notebook list the options and these codes in the terminal.

Help for Querlyn 0.1.0. All help topics