The websites I operate are flat-file based, so when I want to store data it's easiest to write it in csv format. But it's not particularly easy to make queries on this data without additional software.

I'd rather not fire up Open Office or try to figure out how to make awk parse a quoted excel-format file, so I wrote 'csql', which reads a csv file into an in-memory sql database, performs a query, and then writes the result also in csv format.

A short example:

rsvp.csv:

Buffy Summers,false,0
Xander Harris,true,2
Willow Rosenberg,true,1

rsvp.cols:

name text
attend boolean
count integer

Performing queries:

$ csql rsvp.csv 'select sum(count) from t where attend="true"'
3
$ csql rsvp.csv 'select name from t where attend="true"'
Xander Harris
Willow Rosenberg

Files currently attached to this page:

csql3.4kB