Skip to content

CLI Reference

sqb query

Run ad hoc SQL queries against the project database.

Execute ad hoc SQL against the active project connection. Useful for inspecting data, debugging models, or running one-off queries without leaving the SQLBuild CLI.

sqb --project-dir <path> query "SELECT * FROM dev.fact_orders LIMIT 5"

Or from a file:

sqb --project-dir <path> query --file my_query.sql

File paths are resolved from the current working directory.

Flag Description
sql SQL to execute (positional argument)
--file Read SQL from a file instead of the command line
--format Output format: long (default), table, json, or csv
--limit Maximum rows to return (default: 20)
--no-limit Disable the row limit

Vertical record format, one field per line:

-[ RECORD 1 ]---------------------------+
order_id | 1
customer_id | 100
status | completed
-[ RECORD 2 ]---------------------------+
order_id | 2
customer_id | 200
status | completed
2 rows

Horizontal table format:

order_id | customer_id | status
-------- | ----------- | ---------
1 | 100 | completed
2 | 200 | completed
2 rows

JSON array of objects:

[{"order_id": 1, "customer_id": 100, "status": "completed"}]

Standard CSV with headers:

order_id,customer_id,status
1,100,completed
2,200,completed
# Quick inspection with default format
sqb query "SELECT * FROM dev.fact_orders"
# Table format with higher limit
sqb query "SELECT * FROM dev.dim_customers" --format table --limit 50
# Export to JSON
sqb query "SELECT * FROM dev.daily_revenue" --format json --no-limit
# Run SQL from a file
sqb query --file debug_query.sql