Interview practice question
Upserting records into Postgres from Python
Data Engineering · Python · Intermediate
You need to upsert 2 million records into a Postgres table from Python. How do you do it efficiently?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Row-by-row INSERT is too slow.
- Bulk load into a staging table with COPY.
- Then run INSERT ... ON CONFLICT DO UPDATE from staging.
- Do it in a transaction.
- Batch if needed and analyze the table after.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.