https://github.com/uaraven/csql
Comma-separated sql. Console app allowing to run SQL queries on CSV-files
https://github.com/uaraven/csql
csv sql
Last synced: about 2 months ago
JSON representation
Comma-separated sql. Console app allowing to run SQL queries on CSV-files
- Host: GitHub
- URL: https://github.com/uaraven/csql
- Owner: uaraven
- License: apache-2.0
- Created: 2022-10-31T23:52:49.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-13T22:18:38.000Z (8 months ago)
- Last Synced: 2025-08-14T00:15:36.335Z (8 months ago)
- Topics: csv, sql
- Language: Go
- Homepage:
- Size: 5.45 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# csql - Query language for comma-separated values
csql is a small tool allowing to run SQL queries on CSV files.
csql is not particularly fast or flexible, it exists solely because at one moment I though "wouldn't it be nice to run sql queries on csv files". Of course there's probably a ton of existing ways to do it, but reinventing the wheel is one of my favourite pastimes, so here we go.
csql supports basic* `SELECT` statement features, including:
- Joins
- Left, Right, Full, Cross and Inner
- UNION and UNION ALL
- LIKE conditions
- MATCH conditions (like LIKE, but using regular expressions)
- BETWEEN conditions
- IN (...list...) conditions
- Logical operators `AND`, `OR` and `NOT`
- Aggregate functions and HAVING expression
- LIMIT and ORDER BY
- Table and column aliases (`SELECT t.column as col FROM "Table.csv" T`)
- SELECT ... INTO
csql automatically converts values to integer and float types and nulls.
See [this document](docs/syntax.md) for detailed description of Csql syntax.
---
* IN (select) is not supported yet in version 0.2.x
## Usage
For interactive mode run `csql` command and the CSQL shell will start.
You can type SELECT queries or commands. Queries must start with word `select` and terminate with a semicolon (`;`).
Supported commands are:
- help - display help message
- clear - clear screen
- exit - exit csql shell
- ls - list files in the current directory
- pwd - show current directory
- cd - change directory
- csv - set CSV parsing options
- inspect - inspect a CSV file - print out column names and data types of the first row
CSQL can also execute queries passed from the command line
$ csql -c "SELECT * FROM file.csv WHERE column = 'value'" -o result.csv
## Building
csql is a simple Go project, so it can be built as any other Go application
$ go test ./...
$ go build
Or use `build.sh` script to build for all supported platforms. Results will be placed in the `/bin` folder.
### Changing grammar
csql uses ANTLR4 parser generator. ANTLR is a Java application and so you will need Java if you changed the grammar.
Run `antlr/generate.sh` from the project root to build parser from the `Csql.g4` grammar file.