Hier sind einige bemerkenswerte Details:
- Die Staging-Tabelle ist eine einfache Tabelle ohne Indizes oder Schlüssel.
- Die endgültige Tabelle enthält Schlüssel und Indizes.
- Das Problem tritt nicht regelmäßig auf. Manchmal funktioniert die Datenübertragung einwandfrei, aber manchmal kommt es zu Datenverlust.
Code: Select all
import pg8000
...
bigSql = f"INSERT INTO final_tbl({sqlCols}) SELECT {sqlCols} FROM staging_tbl"
print(' ->Inserting data...')
limit = 4000000
offset = 0
while True:
cursor.execute(bigSql+f" LIMIT {limit} OFFSET {offset}")
print('Inserted ', cursor.rowcount)
if cursor.rowcount==0:
break
offset += limit
connection.commit()