On this page
Get Involved
Edit on GitHub

steampipe query

Execute SQL queries interactively, or by a query argument.

To open the interactive query shell, run steampipe query with no arguments. The query shell provides a way to explore your data and run multiple queries.

If a query string is passed on the command line then it will be run immediately and the command will exit. Alternatively, you may specify one or more files containing SQL statements. You can run multiple SQL files by passing a glob or a space-separated list of file names.

If the Steampipe service was previously started by steampipe service start, steampipe will connect to the service instance - otherwise, the query command will start the service. At the end of the query command or session, if other sessions have not connected to the service already, the service will be shutdown. If other sessions have already connected to the service, then the last session to exit will shutdown the service.

Usage

Run Steampipe interactive query shell:

steampipe query [flags]

Run a batch query:

steampipe query {query} [flags]

Flags

Argument Description
--export string Export query output to a file. You may export multiple output formats by entering multiple --export arguments. If a file path is specified as an argument, its type will be inferred by the suffix. Supported export formats are sps (snapshot).
--header string Specify whether to include column headers in csv and table output (default true).
--help Help for steampipe query.
--output string Select the console output format. Possible values are line, csv, json, table, snapshot (default table) .
--pipes-host Sets the Turbot Pipes host used when connecting to Turbot Pipes workspaces. See PIPES_HOST for details.
--pipes-token Sets the Turbot Pipes authentication token used when connecting to Turbot Pipes workspaces. See PIPES_TOKEN for details.
--progress Enable or disable progress information. By default, progress information is shown - set --progress=false to hide the progress bar.
--query-timeout int The query timeout, in seconds. The default is 0 (no timeout).
--search-path strings Set a comma-separated list of connections to use as a custom search path for the query session.
--search-path-prefix strings Set a comma-separated list of connections to use as a prefix to the current search path for the query session.
--separator string A single character to use as a separator string for csv output (defaults to ",")
--share Create snapshot in Turbot Pipes with anyone_with_link visibility.
--snapshot Create snapshot in Turbot Pipes with the default (workspace) visibility.
--snapshot-location string The location to write snapshots - either a local file path or a Turbot Pipes workspace
--snapshot-tag string=string Specify tags to set on the snapshot. Multiple --snapshot-tag arguments may be passed.
--snapshot-title string=string The title to give a snapshot when uploading to Turbot Pipes.
--timing=string Enable or disable query execution timing: off (default), on, or verbose
--workspace-database Sets the database that Steampipe will connect to. This can be local (the default) or a remote Turbot Pipes database. See STEAMPIPE_WORKSPACE_DATABASE for details.

Examples

Open an interactive query console:

steampipe query

Run a specific query directly:

steampipe query "select * from aws_s3_bucket"

Run a query and save a snapshot:

steampipe query --snapshot "select * from aws_s3_bucket"

Run a query and share a snapshot:

steampipe query --share "select * from aws_s3_bucket"

Run the SQL command in the my_queries/my_query.sql file:

steampipe query my_queries/my_query.sql

Run the SQL commands in all .sql files in the my_queries directory and concatenate the results:

steampipe query my_queries/*.sql

Run a query and report the query execution time:

steampipe query "select * from aws_s3_bucket" --timing

Run a query and report the query execution time and details for each scan:

steampipe query "select * from aws_s3_bucket" --timing=verbose

Run a query and return output in json format:

steampipe query "select * from aws_s3_bucket" --output json

Run a query and return output in CSV format:

steampipe query "select * from aws_s3_bucket" --output csv

Run a query and return output in pipe-separated format:

steampipe query "select * from aws_s3_bucket" --output csv --separator '|'

Run a query with a specific search_path:

steampipe query --search-path="aws_dmi,github,slack" "select * from aws_s3_bucket"

Run a query with a specific search_path_prefix:

steampipe query --search-path-prefix="aws_dmi" "select * from aws_s3_bucket"