I am trying to figure out a way to check data I am loading into a SQL table from a dataframe so I can load missing data and avoid loading duplicate data.
Here is a really rough idea.
sql_data = []
data = [(2020-01-01, Monday, 20, 0.1), (2020-01-02, Tuesday, 12, 0.4), (2020-01-01, Wednesday, 26, 0.3)]
cursor.execute('''Select * FROM Table ''')
for row in cursor.fetchall():
sql_data.append(row)
if data in sql_data:
pass
else:
query = '''INSERT INTO Table (Time, Day, Number, Decimal)
VALUES (?, ?, ?, ?)'''
cursor.execute(query, data)
conn.commit()
question from:
https://stackoverflow.com/questions/65851661/is-there-a-way-to-check-and-load-missing-data-to-sql 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…