Skip to main content

Output Modes

See also:
[exec] [shell]

Results returned from StackQL queries can be formatted in tabular (table) format, as well as json or csv format. JSON and CSV formats can be used to interchange data with other programs. The desired output format is configured using the --output StackQL flag.

table Output Format

Results can be formatted in a table format using the table value for the --output parameter as shown below (this is the default value for the StackQL interactive shell):

stackql exec "select id, name from google.compute.instances \
where project = 'stackql-demo' \
and zone = 'australia-southeast1-a'" \
--keyfilepath stackql-demo.json --output table

|---------------------|-----------------|
| ID | NAME |
|---------------------|-----------------|
| 1257085253691867467 | demo-instance-1 |
|---------------------|-----------------|
| 2586731219281477960 | demo-instance-2 |
|---------------------|-----------------|
| 5584456226809282885 | demo-instance-3 |
|---------------------|-----------------|

json Output

Results can be returned in JSON format using the json value for the --output parameter as shown below, this output format is useful if the results of a query need to be passed to an external process or script:

stackql exec "select id, name from google.compute.instances \
where project = 'stackql-demo' \
and zone = 'australia-southeast1-a'" \
--keyfilepath stackql-demo.json --output json

[{"id":"5584456226809282885","name":"demo-instance-3"}
,{"id":"1257085253691867467","name":"demo-instance-1"}
,{"id":"2586731219281477960","name":"demo-instance-2"}]

csv Output

Results can be returned in JSON format using the csv value for the --output parameter as shown below, this output format is useful for parsing results in Excel or providing a data interface to another system:

stackql exec "select id, name from google.compute.instances \
where project = 'stackql-demo' \
and zone = 'australia-southeast1-a'" \
--keyfilepath stackql-demo.json --output csv

id,name
1257085253691867467,demo-instance-1
2586731219281477960,demo-instance-2
5584456226809282885,demo-instance-3

Csv Output Example (with alternative delimiter)

An alternatate delimiter can be specified for the csv output format using the -d switch as shown below:

stackql exec "select id, name from google.compute.instances \
where project = 'stackql-demo' \
and zone = 'australia-southeast1-a'" \
--keyfilepath stackql-demo.json --output csv -d "|"

id|name
1257085253691867467|demo-instance-1
2586731219281477960|demo-instance-2
5584456226809282885|demo-instance-3