I have an sqlite file with a certain table of close to 6 millions rows. For a certain script I need this entire table read at once. When using a query to select the entire table I get a MemoryError.
Loading up to 4 millions rows goes fine using the query:
query = "select * from event where NAME NOT IN (%s) limit 4000000" % placeholders
cursor.execute(query, list_excluded_events)
Using:
print('The lenght of the results in bytes = ' + str(sys.getsizeof(results)))
Gives me the size of the result: 17873392 bytes or 17 MB.
I have 4GB memory allocated to pycharm so 2 million of the same rows should be no problem. So why do I keep getting memory errors?
import sqlite3
import sys
def connection(table, *args):
conn = sqlite3.connect(
table)
cursor = conn.cursor()
if args != ():
list_excluded_events = args[0]
# <- Connect to the database using the variable declared in main
placeholder = '?'
placeholders = ', '.join(placeholder for unused in list_excluded_events)
query = "select * from event where NAME NOT IN (%s) limit 4500000" % placeholders
cursor.execute(query, list_excluded_events)
else:
cursor.execute("select * from event")
results = cursor.fetchall()
#print(results)
results = [list(elem) for elem in results] # <- Change list of tuples to a list of lists
print('The lenght of the results in bytes = ' + str(sys.getsizeof(results)))
return results