RaisDBRaisDB
CLI

Scripting

Pipe RaiseDB into your existing toolchain — JSON output, files, exit codes, env vars.

Output formats

The global --format flag accepts table (default), json, or csv. JSON looks like:

{ "columns": [...], "rows": [...], "row_count": N, "affected_rows": N, "elapsed_ms": N }

Load SQL from a file

query only

raisdb query main @./report.sql

Any sql argument starting with @ is read as a file path. (Doesn't work in \i — that's a different mechanism.)

Repeatable runs with env vars

export RAISDB_CONNECTION=main
export RAISDB_DATABASE=app
raisdb query "" "SELECT count(*) FROM orders"

Exit codes

CodeMeaning
0Success
1doctor found an issue, or connections list was empty
2Missing RAISDB_CONNECTION (no env, no positional)
3query blocked by the SQL safety checker

Piping examples

JSON for downstream tooling

raisdb query main "SELECT id, email FROM users" --format json | jq '.rows[].email'

CSV export

raisdb query main "SELECT * FROM orders WHERE date >= '2024-01-01'" --format csv > orders.csv

Cron / CI

0 * * * * raisdb query prod \
  "SELECT count(*) FROM errors WHERE created_at > NOW() - INTERVAL '1 hour'" \
  --format json

Combining with the shell

Inside raisdb shell, \i <file> runs a SQL file with the session's connection context — useful for interactive one-offs. For non-interactive scripts, prefer raisdb query @file.

On this page