format

The .format command sets the output format for query results in rsql. This allows you to tailor the display for readability, data export, or integration with other tools. The default format is psql, but many formats are available for different use cases.

Usage

.format [format]

Available Formats

FormatDescription
asciiASCII characters to draw a table
csvComma Separated Values (CSV)
expandedPostgreSQL Expanded Format
htmlHyperText Markup Language (HTML)
jsonJavaScript Object Notation (JSON)
jsonlJSON Lines (JSONL)
markdownMarkdown
plainColumn based layout
psqlPostgreSQL Standard Format
sqliteSQLite formatted table
tsvTab Separated Values (TSV)
unicodeUnicode characters to draw a table
xmlExtensible Markup Language (XML)
yamlYAML Ain’t Markup Language (YAML)

When to use

  • Use unicode, ascii, or psql for interactive exploration.
  • Use csv, tsv, json, jsonl, xml, or yaml for exporting data or integrating with other tools.
  • Use markdown or html for documentation or reporting.
  • Use expanded for wide tables or when you want each row displayed vertically.

Examples

Show the current format mode:

.format

Set the format mode to ascii:

.format ascii

Set the format mode to json for machine-readable output:

.format json

Troubleshooting

  • If output looks garbled in your terminal, try switching to ascii or plain.
  • For large exports, prefer csv, tsv, or jsonl for best performance.

Demonstration