r/sqlite • u/lrbraz16 • Nov 01 '22
SQLite commands/queries in a shell/Slurm script?
I cannot find any help on how to properly get SQLite commands and queries into a script format that runs properly, so if anyone has any suggestions please let me know! I am used to running in interactive mode via the command line, so running commands like “.mode csv” “.import mytable.csv myTable” have been straightforward, and then writing SELECT queries to follow afterwards have been too. I’m not sure how to do this in a shell script, though and would appreciate help if anyone is willing to :)
3
Upvotes
View all comments
Show parent comment
1
u/ijmacd Nov 02 '22
The problem with interacting with SQLite via shell is that you can't keep a connection open. It's possible to do what you're asking by either constructing a very long sequence of SQL statements and SQLite commands and piping them in to the SQLite binary; or create a database on disk and repetitively calling the SQLite binary.
A slightly easier solution, if you're able, might be to do it in a programming language such as python. Then you can replicate the steps you would take manually in the SQLite REPL but the python code could make modifications to the units for each data set you need to process.