Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite-utils bulk command #375

Closed
simonw opened this issue Jan 9, 2022 · 3 comments
Closed

sqlite-utils bulk command #375

simonw opened this issue Jan 9, 2022 · 3 comments
Labels
Milestone

Comments

@simonw
Copy link
Owner

simonw commented Jan 9, 2022

The .executemany() method is a very efficient way to execute the same SQL query against a huge list of parameters.

sqlite-utils insert supports a bunch of ways of loading a list of dictionaries - from CSV, TSV, JSON, newline JSON and more thanks to:

What if you could load a list of dictionaries and provide a SQL query with :named parameters that correspond to keys in those dictionaries instead?

This would need to be a new command - I thought about adding a --sql option to insert but that doesn't make sense as that command already requires a table name.

@simonw simonw added enhancement New feature or request research cli-tool labels Jan 9, 2022
@simonw
Copy link
Owner Author

simonw commented Jan 9, 2022

cat blah.csv | sqlite-utils bulk blah.db - \
   "insert into blah (:foo, :bar)" --csv

@simonw
Copy link
Owner Author

simonw commented Jan 10, 2022

I tested the prototype like this:

sqlite-utils blah.db 'create table blah (id integer primary key, name text)' 
echo 'id,name
1,Cleo
2,Chicken' > blah.csv
sqlite-utils bulk blah.db 'insert into blah (id, name) values (:id, :name)' blah.csv --csv

@simonw simonw mentioned this issue Jan 10, 2022
4 tasks
@simonw simonw added this to the 3.21 milestone Jan 10, 2022
@simonw simonw changed the title Idea: sqlite-utils bulk command sqlite-utils bulk command Jan 11, 2022
@simonw simonw closed this as completed in 1291415 Jan 11, 2022
@simonw
Copy link
Owner Author

simonw commented Jan 11, 2022

simonw added a commit that referenced this issue Jan 11, 2022
simonw added a commit that referenced this issue Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant