Skip to content

Query Command

The query command executes and retrieves the results of a query on a specified connection and returns the results in table format, JSON, or CSV.

You can run it in three modes:

  • Direct query: provide --connection and --query
  • Asset query: provide --asset (optional --environment) to execute the SQL from an asset file
  • Auto-detect: provide --asset + --query to run an ad-hoc query using the asset's connection and dialect

Flags:

FlagAliasDescription
--connection-cThe name of the connection to use (direct query mode).
--query-qThe SQL query to execute.
--assetPath to a SQL asset file within a Bruin pipeline.
--environment--envTarget environment name as defined in .bruin.yml.
--start-dateStart date for query variables in YYYY-MM-DD or YYYY-MM-DD HH:MM:SS.
--end-dateEnd date for query variables in YYYY-MM-DD or YYYY-MM-DD HH:MM:SS.
--limit-lLimit the number of rows returned.
--timeout-tTimeout for query execution in seconds (default: 1000).
--output [format]-oOutput type: plain, json, csv.
--config-fileThe path to the .bruin.yml file.

Example

bash
bruin query --connection my_connection --query "SELECT * FROM table"

Example output:

plaintext
+-------------+-------------+----------------+
|   Column1   |   Column2   |    Column3     |
+-------------+-------------+----------------+
| Value1      | Value2      | Value3         |
| Value4      | Value5      | Value6         |
| Value7      | Value8      | Value9         |
+-------------+-------------+----------------+