advancedTop 30 Scenario-Based Questions
You need to merge (upsert) customer records from a CSV import — insert new, update existing. How in PostgreSQL?
PostgreSQL 15+ MERGE statement: MERGE INTO customers AS target USING staging_customers AS source ON target.email = source.email WHEN MATCHED THEN UPDATE SET name=source.name, phone=source.phone, updated_at=NOW() WHEN NOT MATCHED THEN INSERT (email, name, phone, created_at) VALUES (source.email, source.name, source.phone, NOW()); PostgreSQL INSERT ON CONFLICT (all versions): INSERT INTO customers (
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.
You need to merge (upsert) customer records from a CSV import — insert new, update existing. How in PostgreSQL?