Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C csvkit
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 61
    • Issues 61
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • wireservice
  • csvkit
  • Issues
  • #813
Closed
Open
Issue created Mar 25, 2017 by Administrator@rootContributor

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.

Assignee
Assign to
Time tracking