PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Panda aggiorna sql

Considera un tavolo temporaneo che sarebbe la replica esatta del tuo tavolo finale, ripulito ad ogni corsa:

engine = create_engine('postgresql+psycopg2://user:[email protected]')
df.to_sql('temp_table', engine, if_exists='replace')

sql = """
    UPDATE final_table AS f
    SET col1 = t.col1
    FROM temp_table AS t
    WHERE f.id = t.id
"""

with engine.begin() as conn:     # TRANSACTION
    conn.execute(sql)