I have a 30 GB SQLite 3 database with a table containing 25 million rows. I want to group the table by a string column and create a new table for every group of records, named after the string and containing all columns.
Is this possible with Python and SQLite 3? I could process chunks in Python, but is there a SQL command?
Start table
all_entries
a b c d
hi 4 234 lala
bye 7 342 lulu
bye 5 433 abc
bye 4 234 abd
hi 56 435 abc
hi 3 455 a
Result Tables
bye
a b c d
bye 7 342 lulu
bye 5 433 abc
bye 4 234 abd
hi
a b c d
hi 4 234 lala
hi 56 435 abc
hi 3 455 a
Best Answer
This can be achieved as follows according to the official SQLite documentation.
For the
bye
table you could use the following:...and for the
hi
table:Reference: CREATE TABLE (SQL As Understood By SQLite)
If this is just a temporary solution for something you wish to achieve then add the
TEMPORARY
keyword:There are some limitations with this approach which are described in the referenced article.
And you would possibly have to post a question on Stack Overflow for a Python solution.