Skip to content

danchoi/tsvsql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tsvsql

Templates TSV values into a SQL template

input.tsv:
apple 1
banana 2

$ tsvsql 'INSERT into fruits (name, price) VALUES ($1, $2:num);' < input.tsv 
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 'INSERT into fruits (name, price) VALUES ($1, $2:num);' < input2.tsv 
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" and "1" are true, "f" and "0" are false

The placeholders start counting the first TSV value from position 1, not
zero.

About

Template TSV into SQL templates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published