Linux command
trdsql 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Query CSV
trdsql "SELECT * FROM [file.csv]"
Query JSON
trdsql -ijson "SELECT * FROM [file.json]"
Output as JSON
trdsql -ojson "SELECT * FROM [file.csv]"
With header
trdsql -ih "SELECT name FROM [file.csv]"
Join files
trdsql "SELECT * FROM [a.csv] JOIN [b.csv] ON [a.id]=[b.id]"
Query LTSV
trdsql -iltsv "SELECT * FROM [file.ltsv]"
Output as Markdown table
trdsql -omd "SELECT * FROM [file.csv]"
Query YAML
trdsql -iyaml "SELECT * FROM [file.yaml]"
说明
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.
参数
- -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.
FAQ
What is the trdsql command used for?
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.
How do I run a basic trdsql example?
Run `trdsql "SELECT * FROM [file.csv]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -i _FORMAT_ do in trdsql?
Input format (csv, json, ltsv, yaml, tbln).