Support "create table if not exists"
Created by: jez
When importing multiple CSV files into a SQL (which all share the same table schema), it would be great if csvsql used CREATE TABLE IF NOT EXISTS foo
.
Current vs. Desired Usage
Consider this shell code, which dynamically generates CSV files (say, by making requests to a JSON API, munging the data, and spitting out a CSV file):
for thing in $THINGS; do
# ...
# process $thing, generate $thing.csv
# ...
# Load $thing.csv into SQLite database
csvsql --db sqlite:///foo.db --insert $thing.csv
done
This will currently fail for every loop iteration after the first $thing
, because it uses this SQL to create the table:
CREATE TABLE ... (
...
);
Ideally, I'd be able to have a flag like --create-if-not-exists
(substitute the name of your choice here, like --create
, --create-force
, --create-silent
, etc.), which generates this SQL:
CREATE TABLE IF NOT EXISTS ... (
...
);
Implementation Considerations
It's possible this change would have to be made in accordance with an upstream change to agate-sql
. If this is not the correct place to report an issue, let me know.
If this is a feature you'd consider, but you don't want to do it yourself, I'd be glad to lend a hand.