trdsql loads CSV, JSON and YAML files into a database, then runs your SQL in SQLite, PostgreSQL or MySQL
CLI tool that can execute SQL queries on CSV, LTSV, JSON, YAML and TBLN. Can output to various formats.
At a glance
- What is it?
- trdsql is a Go command line tool that executes SQL on CSV, LTSV, JSON, YAML and TBLN files and writes the result in many formats. This article covers the driver choice behind the SQL dialect, the input and output flags, the CGO-free build and the install routes.
- Who is it for?
- Use trdsql when you want SQL joins and aggregates over CSV, JSON, YAML or LTSV files from a shell script, and when PostgreSQL or MySQL syntax matters to you. Skip it for files too large for the database driver you pick.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 18 days ago.
- What is it written in?
- Mainly Go, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- noborus/trdsql2,174 ★ · -2
| Repository | 2026-10-08 | 2026-11-25 |
|---|---|---|
| noborus/trdsql | 2.2k | 2.2k |
-2 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
SQL runs in a real database driver, and sqlite3 is the default
trdsql reads the input files into a database and runs your query there. The -driver flag picks which one, from mysql, postgres, sqlite3 and sqlite, and the default is sqlite3. The sqlite value is the CGO-free build. The flags -db, -dblist, -dsn and -config choose a database configuration and connection.
The README draws its one line of comparison with q and textql, two similar tools, and states a key distinction: trdsql allows the use of PostgreSQL or MySQL syntax. That sentence is the reason the driver flag exists. With the default driver, you write SQLite SQL. With postgres or mysql, the query is executed by that server, so its functions and join behaviour apply.
The consequence is that the same query can behave differently depending on -driver, and a script that omits the flag depends on the default. The README has sections on PostgreSQL and MySQL usage, including joining a database table with a CSV file, which the README labels as possible.
The limit is that PostgreSQL and MySQL modes need a running server and a DSN, so they are not a zero-setup path. The default sqlite3 driver needs nothing beyond the binary.
A file can be a table name, and a bare file name converts formats
The usage line is short:
trdsql [options] SQLIn the SQL, a file name acts as a table. For pure conversion, you can skip SQL entirely. The README states that file conversion is equivalent to executing a SELECT star from the filename, written as:
trdsql -o[output format] -t [input filename]The -t flag reads the table name from the specified file, and -q reads the whole query from a file. That makes trdsql a format converter first: a CSV goes to JSON, JSONL, YAML, LTSV, a Markdown table or an ASCII table by changing the output flag.
The input format is guessed from the extension by default through -ig. That default is convenient for files named .csv or .json, and it is wrong for a file with no telling extension or a misleading one. In that case set the input flag explicitly: -icsv, -ijson, -iltsv, -iyaml, -itbln, -iwidth, -itext or -ilogfmt.
For data arriving on a pipe, the README has a STDIN input example. There is no file extension to guess from on a pipe, so the input flag is the way to say what the bytes are.
Input options shape the table before SQL sees it
A handful of flags change how rows are read. -ih treats the first line as column names, and the README marks it CSV only. -id sets the field delimiter, default comma, also CSV only. -is skips a header row, -ilr limits the number of rows read, and -inum adds a row number column. -inull names a string to convert to NULL on input, which matters because the README has a separate section on the handling of NULL.
For JSON and JSONL, -ijq takes a jq expression. This lets you reach into nested JSON and present an array of objects as a table, instead of querying a deeply nested document directly. The jq support comes from the gojq library in go.mod.
The -ir flag sets the number of rows to preread, default 1. The preread decides the column set, and the README includes an example titled Columns is not constant, so for files where later rows have more fields than the first, raising the number is the lever to try.
The cost of all this is reading everything into a database before the query runs. A query that needs one column from a huge file still pays for loading it, and the README gives no figures on memory or throughput, so measure on your own data.
Output formats range from CSV default to vertical and Markdown
CSV is the default output. The flags -ocsv, -otsv, -ojson, -ojsonl, -oltsv, -oyaml, -oat for an ASCII table, -omd for Markdown, -oraw for raw output and -ovf for vertical format cover the visible list, and the README's example section also covers TBLN, WIDTH, TEXT and logfmt.
Two outputs matter for day-to-day shell use. -oat prints an aligned ASCII table that is readable in a terminal, and -omd prints a Markdown table to paste into an issue or a document. The table writer comes from the olekukonko/tablewriter dependency.
Output can go to a file, and the README has examples for output compression and for guessing the format from the output file name. A name ending in .json can select JSON output without a separate flag. Compression support comes through libraries listed in go.mod: klauspost/compress, dsnet/compress, pierrec/lz4 and ulikunitz/xz, which fits the README's sections on compressed input and output files.
The list in the README is cut off after -oyaml in the global options, so more output options, such as the output options subsection, are in the full file. Check the README for header, delimiter and quoting controls before assuming your preferred CSV dialect is available.
The CGO-free build trades cross-compiling ease for slower execution
The default build uses go-sqlite3, which needs CGO. The README offers an alternative: when building with CGO_ENABLED=0, use the sqlite package from modernc.org, selected at run time with -driver sqlite. Building without CGO can reduce issues related to cross-compiling, though it may result in slower execution times.
The Makefile shows the other side. Its TAGS value is sqlite_math_functions, passed to go build and go test, which turns on SQLite's math functions in the CGO build. The make pkg target sets CGO_ENABLED=1 and builds a zip with the binary, README.md, LICENSE and config.json.sample. Its comments show a cross build with a zig cc compiler: CC="zig cc -target x86_64-windows" make pkg GOOS=windows GOARCH=amd64.
The practical rule follows. If you download a release binary, the choice is already made. If you build from source on a platform without a C toolchain, use CGO_ENABLED=0 and accept slower queries, and note the math function tag belongs to the CGO path. The README does not state whether the CGO-free driver supports the same functions, so test any function you depend on.
The go.mod declares go 1.25.0, and the README requires Go 1.25 or higher for go get.
Five install routes, and the Docker build file pins an older Go
Install from source with the README's go get sequence:
go get -d github.com/noborus/trdsql
cd $GOPATH/src/github.com/noborus/trdsql
make
make installOther routes are the releases page for Linux, Windows and macOS binaries, brew install trdsql for Homebrew, sudo port selfupdate followed by sudo port install trdsql for MacPorts, and pkg install trdsql for FreeBSD.
Docker has three steps. Pull with docker pull noborus/trdsql, or build with docker build -t trdsql . and run it:
docker run --rm -it -v $(pwd):/tmp trdsql [options and commands]The volume mount maps the current directory to /tmp in the container, so file names in your query are relative to what the container sees.
There is a mismatch to know about. The Dockerfile builds from golang:1.18-alpine, clones the repository at depth 1 and runs make, while go.mod declares go 1.25.0. A local docker build therefore starts from a much older toolchain than the module asks for, and the README does not say whether that works, so prefer docker pull for the published image.
The three most recent releases are v1.2.3 and v1.2.2, both on 2026-05-29, and v1.2.1 on 2026-05-12. The last push was on 2026-10-18.
The same code is a Go library, and analyze suggests SQL for an unknown file
Beyond the CLI, trdsql is importable. The README sends library users to the godoc on pkg.go.dev and to the provided examples, and the repository holds _example/ and example_test.go. The top-level file names show the architecture: importer files for CSV, JSON, LTSV, TBLN, text, YAML, logfmt and slices, exporter and output files for the formats, and database files for connection.
One flag helps with unfamiliar data. -a filename analyzes the file and suggests SQL, and -A does the same while only suggesting SQL without running it. For a file with many columns of unknown meaning, that gives a starting query that you then edit.
A separate analyze.go and keywords.go sit in the repository. The sqlss dependency, also from the same author, appears in go.mod. The README does not say how the suggestion is built, so treat the output as a draft.
A configuration file, config.json.sample, ships with the repository for database settings, and the -config flag points at one. The README has a Configuration section under SQL for it.
The license is MIT, and the homepage is noborus.github.io/trdsql.
Editorial conclusion
Use trdsql when you want SQL joins and aggregates over CSV, JSON, YAML or LTSV files from a shell script, and when PostgreSQL or MySQL syntax matters to you. Skip it for files too large for the database driver you pick. Before relying on it, check which driver is active with -driver, because the default is sqlite3 and the SQL dialect follows that choice.
Frequently asked questions
What is trdsql?
trdsql is a CLI tool written in Go that executes SQL queries on CSV, LTSV, JSON, YAML and TBLN files and can output to various formats.
How does trdsql differ from q and textql?
The README calls it similar to q and textql, with a key distinction: it allows the use of PostgreSQL or MySQL syntax.
How do I install trdsql?
Use brew install trdsql, sudo port install trdsql, pkg install trdsql on FreeBSD, a release binary, docker pull noborus/trdsql, or go get with make. Go 1.25 or higher is required to build.
Which database drivers does trdsql support?
The -driver flag accepts mysql, postgres, sqlite3 and sqlite, which is the CGO-free build. The default is sqlite3.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/noborus-trdsql)Star history chart for your README
[](https://hysenlabs.com/projects/noborus-trdsql)Was this useful?