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 (

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Explain the difference between creating an index before vs after bulk loading data.← Back to all SQL questions