3

I have an SQLite database on this form:

Table1

Column1 | Column 2 | Column 3 | Column 4

I want to populate this database with data stored in some hundred .out files in this form, where every file has millions of rows:

value1;value2;value3;value4;
2value1;2value2;2value3;2value4;
... etc

Is there a fast way to populate the database with these data? One way would be to read in the data line for line in python and insert, however there probably should be a faster way to just input the whole file?

Bash, SQLite, Python preferrably

2

1 Answer 1

7

SQLite has a .import command.

.import FILE TABLE Import data from FILE into TABLE

You can use it like this (shell).

for f in *.out
do
    sqlite3 -separator ';' my.db ".import $f Table1"
done
Sign up to request clarification or add additional context in comments.

2 Comments

Is it a problem that every line ends with a ; ? I get "expected 7 columns but found 8 - extras ignored". Do you think this slows down the process in any way?
I don't know. You could strip the trailing ; first and try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.