Table of content
- What is sql4csv?
- Why your own solution and not using an existing ones?
- Download and Installation
To execute a SQL statement on a CSV file simple execute the following command:
scq select distinct author from books.csv
scq is the name of the command to execute.
In case of a CSV file looking like the following
author,title Douglas Adams,Doctor Who Douglas Adams,The Hitchhiker's Guide to the Galaxy Terry Pratchet,The Colour of Magic Terry Pratchet,Mort
the result, printed in the console will be
author Douglas Adams Terry Pratchet
Because I can :-)
There are a bunch of tools out there to do such a solution. The most impressive is
is written by me to have a project using the new features of Java 8 from scratch.
Also I want to do some automatic type detection for lazy types like dates and datetimes. Reason are the CSV files I sometimes have where dates are written in an ISO like format (2016-8-3 instead of 2016-08-03).
But why do I need such a tool?
It's for my simple statistic stack based on Unix command line tools, R and some simple SQL scripts which I don't want to import to a dedicated RDBMS for only onetime usage.
- Download the latest prebuild version from our homepage: sql4csv-LATEST-bin.zip.
- Unpack the archive with the tool of your choice.
- Adjust your
PATHenvironment variable by adding the
That's it. Have fun :-)
Using SQL statements direct from a
bash command line is problematic.
bash replaces the asterisk (
*) sign with the files of the current
directory. It's not simple possible to escape this behavior. I work around this
with replaceing the * character with
$(head -n 1 filename)
Not a very elegant method but it works.
Escaping additional special
bash characters like parenthesis or less-
and greater-than equal signs is straight forward with a leading basckslash
scq supports space characters in table columns. Nevertheless if a table
column contains a space surrounded
from, the beahvior is not supported yet.