Skip to main content
InterviewHubPRO
Section Overview
Q10

Question 10 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

20%
PostgreSQL Enterprise (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

What is `UPSERT` in PostgreSQL (`ON CONFLICT DO UPDATE / DO NOTHING`)?

junior LevelCode ExampleDatabases & SQLPostgreSQLBehavioral

In Simple Words: Performs an atomic insert or update if a unique constraint or primary key conflict occurs:

sql
INSERT INTO user_stats (user_id, login_count, last_login)
VALUES (42, 1, NOW())
ON CONFLICT (user_id)
DO UPDATE SET
  login_count = user_stats.login_count + 1,
  last_login = EXCLUDED.last_login;