Output formats

sqx prints a readable table in a terminal and CSV when its output is piped or redirected. Choose any other format with -o.

Available formats

FlagOutputGood for
-o autotable in a terminal, csv when piped (the default)Everyday use
-o tableBoxed ASCII tableReading results
-o csvComma-separated valuesSpreadsheets, other tools
-o tsvTab-separated valuescut, awk, pasting into sheets
-o jsonA JSON array of objectsAPIs, jq, JavaScript
-o jsonlOne JSON object per lineStreaming, log pipelines
-o mdMarkdown tableREADMEs, issues, reports
-o rawValues only, one row per linexargs, shell loops

JSON and JSON Lines

sqx -f u=data/users.csv -o json "SELECT id, name, plan FROM u LIMIT 2"
[
  {
    "id": 1,
    "name": "Asha Rao",
    "plan": "pro"
  },
  {
    "id": 2,
    "name": "Ben Carter",
    "plan": "free"
  }
]
sqx -f u=data/users.csv -o jsonl "SELECT id, name FROM u LIMIT 2"
{"id":1,"name":"Asha Rao"}
{"id":2,"name":"Ben Carter"}

This makes sqx a one-line CSV to JSON converter. It works the other way too: cat data.json | sqx -o csv "SELECT * FROM stdin" converts JSON to CSV.

Markdown

sqx -f u=data/users.csv -o md "SELECT id, name, plan FROM u LIMIT 3" > users.md
| id | name | plan |
| --- | --- | --- |
| 1 | Asha Rao | pro |
| 2 | Ben Carter | free |
| 3 | Chen Wei | pro |

Raw values for shell scripts

raw prints only the values, which is ideal for feeding other commands:

sqx -f u=data/users.csv -o raw "SELECT email FROM u" | xargs -n1 echo mail:

Leaving out the header

Add -no-output-header to drop the header row from csv or tsv output:

sqx -f u=data/users.csv -o csv -no-output-header "SELECT id, name FROM u" >> all_users.csv