tsvsql-0.1.1.0: README
tsvsql
Templates TSV values into a SQL template
input.tsv:
apple 1
banana 2
tsvsql $ < input.tsv dist/build/tsvsql/tsvsql 'INSERT into fruits (name, price) VALUES ($1, $2:num);'
INSERT into fruits (name, price) VALUES ('apple', 1);
INSERT into fruits (name, price) VALUES ('banana', 2);
WARNING: Use single quotes around the SQL template expression so that
Bash does not do interpolation.
'null' text is translated into NULL:
input2.tsv
apple 1
banana null
tsvsql $ < input2.tsv dist/build/tsvsql/tsvsql 'INSERT into fruits (name, price) VALUES ($1, $2:num);'
INSERT into fruits (name, price) VALUES ('apple', 1);
INSERT into fruits (name, price) VALUES ('banana', NULL);
The subtitution placeholders are like this:
$1 # value is a string; the value is quoted and escaped
$2:num # value is a number; not quoted
$3:bool # value is a bool; "t" is true, "f" is false
The placeholders start counting the first TSV value from position 1, not
zero.