LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

trdsql

Execute SQL queries on CSV, JSON, LTSV, YAML, and TBLN files

TLDR

Query CSV
$ trdsql "SELECT * FROM [file.csv]"
copy
Query JSON
$ trdsql -ijson "SELECT * FROM [file.json]"
copy
Output as JSON
$ trdsql -ojson "SELECT * FROM [file.csv]"
copy
With header
$ trdsql -ih "SELECT name FROM [file.csv]"
copy
Join files
$ trdsql "SELECT * FROM [a.csv] JOIN [b.csv] ON [a.id]=[b.id]"
copy
Query LTSV
$ trdsql -iltsv "SELECT * FROM [file.ltsv]"
copy
Output as Markdown table
$ trdsql -omd "SELECT * FROM [file.csv]"
copy
Query YAML
$ trdsql -iyaml "SELECT * FROM [file.yaml]"
copy

SYNOPSIS

trdsql [-i format] [-o format] [options] query

DESCRIPTION

trdsql executes SQL queries directly against structured data files such as CSV, JSON, LTSV, YAML, and TBLN without importing them into a database first. File names are used as table names in SQL statements, making it straightforward to filter, aggregate, and transform data using familiar SQL syntax.The tool supports joining data across multiple files, enabling relational queries between different data sources in a single command. Input and output formats can be specified independently, allowing conversion between formats as a side effect of querying.Under the hood, trdsql uses SQLite as the default query engine but can also connect to PostgreSQL and MySQL for more advanced SQL features. Headers in CSV files can be used as column names with the -ih flag.

PARAMETERS

-i FORMAT

Input format (csv, json, ltsv, yaml, tbln).
-o FORMAT
Output format (csv, json, jsonl, ltsv, raw, md, at, vf, tbln).
-ih
Input has header row.
-oh
Output with header.
-id DELIM
Input delimiter character.
-od DELIM
Output delimiter character.
-driver DRIVER
Database driver (sqlite3, postgres, mysql).
-dsn DSN
Database connection string.
-debug
Show debug output.

CAVEATS

Go-based tool. Large files are loaded into memory. SQL knowledge required. Default database engine is SQLite.

HISTORY

trdsql was created to execute SQL queries against various structured data formats like CSV and JSON.

SEE ALSO

textql(1), q(1), miller(1)

Copied to clipboard
Kai