SQL-like query language for csv
Branch: master
Clone or download
mithrandie Release v1.8.3
- Fix the following bugs.
  - RETURN statement does not return a value in IF and WHILE statements.
  - NOW Function returns different time from the specification in user-defined functions.
Latest commit d545f2a Feb 17, 2019



SQL-like query language for csv

Build Status codecov

csvq is a command line tool to operate CSV files. You can read, update, delete CSV records with SQL-like query.

You can also execute multiple operations sequentially in managed transactions by passing a procedure or using the interactive shell. In the multiple operations, you can use variables, cursors, temporary tables, and other features.


  • CSV File Operation
    • Select Query
    • Insert Query
    • Update Query
    • Delete Query
    • Create Table Query
    • Alter Table Query
  • Cursor
  • Temporary Table
  • Transaction Management
  • Support loading data from Standard Input
  • Support JSON Format
  • Support Fixed-Length Format
  • Support following file encodings
    • UTF-8
    • Shift-JIS (except for JSON Format)

Reference Manual

Reference Manual - csvq


Install executable binary

  1. Download an archive file from release page.
  2. Extract the downloaded archive and add a binary file in it to your path.

Build from source


Go 1.9 or later (ref. Getting Started - The Go Programming Language)

Build with one of the following ways

Use go get
  1. $ go get github.com/mithrandie/csvq
Build with strict dependencies (Go 1.11)
  1. $ go get -d github.com/mithrandie/csvq
  2. Change directory to $GOPATH/github.com/mithrandie/csvq
  3. $ env GO111MODULE=on go install
Build with strict dependencies (Go 1.10 or earlier)
  1. Install Glide (ref. Glide: Vendor Package Management for Golang)
  2. $ go get -d github.com/mithrandie/csvq
  3. Change directory to $GOPATH/github.com/mithrandie/csvq
  4. $ glide install
  5. $ go install


# Simple query
csvq "select id, name from `user.csv`"
csvq "select id, name from user"

# Specify data delimiter as tab character
csvq -d "\t" "select count(*) from `user.csv`"

# Load no-header-csv
csvq --no-header "select c1, c2 from user"

# Load from redirection or pipe
csvq "select * from stdin" < user.csv
cat user.csv | csvq "select *"

# Load from Fixed-Length Format
cat /var/log/syslog | csvq -n -d "[15, 24, 124]" "select *"

# Split lines with spaces automatically
ps | csvq -d spaces "select * from stdin"

# Output in JSON format
csvq -f json "select integer(id) as id, name from user"

# Output to a file
csvq -o new_user.csv "select id, name from user"

# Load statements from file
$ cat statements.sql
VAR @id := 0;
SELECT @id := @id + 1 AS id,
  FROM user;

$ csvq -s statements.sql

# Execute statements in the interactive shell
$ csvq
csvq > UPDATE users SET name = 'Mildred' WHERE id = 2;
1 record updated on "/home/mithrandie/docs/csv/users.csv".
csvq > COMMIT;
Commit: file "/home/mithrandie/docs/csv/users.csv" is updated.
csvq > EXIT;

# Show help
csvq -h

More details >> https://mithrandie.github.io/csvq

Example of cooperation with other applications