PostgreSQL — How to UPSERT safely, easily and fast

Prevent duplicates, insert new records, updated existing ones

Mike Huls
Towards Data Science
4 min readOct 12, 2021

--

In stead of joining roads we’ll be safely joining datasets in our database (image by Sigmund on Unsplash)

When you UPSERT data into a table, you update or ignore records that already exist and insert new ones. After reading this article, you’ll be able to perform a single query in Postgres that allows you to do exactly this. We’ll go through a practical example that demonstrates…

--

--