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
| Flag | Output | Good for |
|---|---|---|
-o auto | table in a terminal, csv when piped (the default) | Everyday use |
-o table | Boxed ASCII table | Reading results |
-o csv | Comma-separated values | Spreadsheets, other tools |
-o tsv | Tab-separated values | cut, awk, pasting into sheets |
-o json | A JSON array of objects | APIs, jq, JavaScript |
-o jsonl | One JSON object per line | Streaming, log pipelines |
-o md | Markdown table | READMEs, issues, reports |
-o raw | Values only, one row per line | xargs, 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