Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/PostgreSQL
PostgreSQLmedium

Postgres UPSERT — what does `ON CONFLICT DO UPDATE` do?

Tags
#upsert#on-conflict#sql
Back to categoryPractice quiz

Answer

It inserts a row, but if it violates a unique constraint/index, it updates the existing row instead. It’s a safe way to “insert or update” in one statement.

INSERT INTO users(email, name)
VALUES ('[email protected]', 'Ada')
ON CONFLICT (email)
DO UPDATE SET name = EXCLUDED.name;

Related questions

PostgreSQL
CTE (`WITH`): what is it and what is a performance gotcha?
#postgres#sql#cte
PostgreSQL
Window functions: what problem do they solve? Give a quick example.
#postgres#sql#window-functions
Databases
Why can `LIKE '%term%'` be slow and what are common alternatives?
#sql#like#indexes
Databases
SQL NULL: why is `col = NULL` not true and what should you use?
#sql#null#three-valued-logic