LinuxCommandLibrary

trdsql

SQL queries on structured data 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

SYNOPSIS

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

DESCRIPTION

trdsql executes SQL queries directly against structured data files such as CSV, JSON, and LTSV 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).
-o FORMAT
Output format.
-ih
Input has header.
-oh
Output header.
-d DELIM
Delimiter.

CAVEATS

Go-based tool. Large files in memory. SQL knowledge needed.

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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community