scenario to update or insert big amount of data I try to find the best scenario to update or insert 1 million contacts in my postgres database.

My actual scenario is:


read contacts 1000 per 1000 and try to insert multiple rows with one request
if my request fails, I go line per line to insert or update my 1000 contacts


It takes 7 minutes for 50K lines.

What is the best scenario to perform my update or insert?
I would do it like this:

Load all data into an empty staging table and use SQL to identify and correct problematic records before moving the data into your database.