Skip to content

query

Run SQL from a string or a file and get rows back as a table, JSON, or CSV. Exactly one input source is required. Passing neither -q nor -f, or both, exits with an error.

PostgreSQL is the only implemented driver today, so queries need a PostgreSQL connection.

Usage

bash
dbmux query [options]

Options

OptionAliasTypeDescription
--sql-qstringSQL text to execute
--file-fstringFile containing SQL to execute
--connection-nstringNamed saved connection to use
--database-dstringDatabase on the same server
--formattable | json | csvOutput format, defaults to table
--limit-lnumberRow limit appended to the query, minimum 1

Automatic row limits

With -l n, dbmux appends LIMIT n to your SQL unless the statement already contains the word limit in any casing. A query that carries its own LIMIT clause passes through untouched.

Output

Rows print in the chosen format, followed by a summary line reporting the row count and duration:

text
Query successful: N rows in Xms

Examples

Run a SELECT with its own limit:

bash
dbmux query -q "SELECT * FROM users LIMIT 10"

Execute a file of statements:

bash
dbmux query -f queries.sql

Get comma separated output:

bash
dbmux query -q "SELECT * FROM users" --format csv

Cap results at 100 rows:

bash
dbmux query -q "SELECT * FROM logs" -l 100

Query through a named connection:

bash
dbmux query -n production -q "SELECT version()"

Related commands

  • list shows databases and tables worth querying.
  • connect saves the connections -n refers to.
  • configuration explains which connection gets picked.