query
A query step runs a database query against a database. Postgres, MySQL, SQLite, and DuckDB databases are currently supported.
Arguments
Argument | Type | Optional? | Description |
---|---|---|---|
sql | String | Required | A SQL query string. |
args | List | Optional | A list of arguments to pass to the query. |
database | String | Optional | The database to query. This may be a connection reference (connection.steampipe.default), a connection string (postgres://steampipe@127.0.0.1:9193/steampipe), or a Pipes workspace (acme/anvils). If not set, the default set in the mod database will be used. |
This step also supports the common step arguments and attributes.
Attributes (Read-Only)
Attribute | Type | Description |
---|---|---|
rows | List of objects | The query results, as an array of row objects |
The rows attribute contains the query result as a list of objects with an item for each row, where the column name is the key and the column value is the value.
For example:
Results in:
Since rows is a list, you can use standard HCL for expressions:
or splats:
to extract data.
More Examples
Steampipe Query
If no database is specified, then the default defined in the mod database will be used. If that is not set, the local Steampipe instance will be used by default.
You can also specify a Steampipe connection to connect to a Steampipe database:
Postgres Query
You can use a Postgres connection to connect to a PostgreSQL database:
Alternatively, you can pass the connection string directly, with the standard URI syntax supported by psql and pgcli:
SQLite query
You can use a SQLite connection to connect to a SQLite database:
Alternatively, pass the connection string directly, in the format sqlite:path/to/file:
The path is relative to the mod location, and // is optional after the scheme, thus the following are equivalent:
DuckDB query
You can use a DuckDB connection to connect to a DuckDB database:
Or pass a connection string directly in the format duckdb:path/to/file:
The path is relative to the mod location, and // is optional after the scheme, thus the following are equivalent:
MySQL Query
You can use a MySQL connection to connect to a MySQL database:
Or pass a connection string directly. The MySQL connection string supports the syntax of the GO SQL driver for MySQL: