Bird
0
0

What does the ON CONFLICT DO NOTHING clause do in a PostgreSQL INSERT statement?

easy📝 Conceptual Q11 of 15
PostgreSQL - Set Operations and Advanced Queries
What does the ON CONFLICT DO NOTHING clause do in a PostgreSQL INSERT statement?
AIt skips inserting the row if a conflict occurs on a unique key.
BIt updates the existing row with new values on conflict.
CIt deletes the conflicting row before inserting the new one.
DIt raises an error and stops the insert operation.
Step-by-Step Solution
Solution:
  1. Step 1: Understand ON CONFLICT behavior

    The ON CONFLICT DO NOTHING clause tells PostgreSQL to ignore the insert if a duplicate key conflict happens.
  2. Step 2: Compare with other conflict actions

    Unlike DO UPDATE which modifies existing rows, DO NOTHING simply skips the insert without error.
  3. Final Answer:

    It skips inserting the row if a conflict occurs on a unique key. -> Option A
  4. Quick Check:

    ON CONFLICT DO NOTHING = skip insert on duplicate [OK]
Quick Trick: DO NOTHING skips duplicates silently, no error thrown [OK]
Common Mistakes:
  • Thinking DO NOTHING updates existing rows
  • Assuming DO NOTHING deletes conflicting rows
  • Believing DO NOTHING raises an error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes