Bird
0
0

Which of the following is the correct syntax to update a column score on conflict for a table players with unique id?

easy📝 Syntax Q3 of 15
PostgreSQL - Set Operations and Advanced Queries
Which of the following is the correct syntax to update a column score on conflict for a table players with unique id?
AINSERT INTO players(id, score) VALUES (1, 100) ON CONFLICT (id) DO NOTHING UPDATE score = 100;
BINSERT INTO players(id, score) VALUES (1, 100) ON CONFLICT DO UPDATE SET score = score + 1;
CINSERT INTO players(id, score) VALUES (1, 100) ON CONFLICT (id) DO UPDATE SET score = EXCLUDED.score;
DINSERT INTO players(id, score) VALUES (1, 100) ON CONFLICT (id) UPDATE SET score = 100;
Step-by-Step Solution
Solution:
  1. Step 1: Check the correct ON CONFLICT syntax

    The syntax requires specifying the conflict target (id) and the action DO UPDATE SET with the new value.
  2. Step 2: Validate the use of EXCLUDED keyword

    EXCLUDED.score refers to the value proposed for insert, which is used to update the existing row.
  3. Final Answer:

    INSERT INTO players(id, score) VALUES (1, 100) ON CONFLICT (id) DO UPDATE SET score = EXCLUDED.score; -> Option C
  4. Quick Check:

    Correct syntax with EXCLUDED = INSERT INTO players(id, score) VALUES (1, 100) ON CONFLICT (id) DO UPDATE SET score = EXCLUDED.score; [OK]
Quick Trick: Use EXCLUDED.column to reference new insert values on conflict [OK]
Common Mistakes:
  • Omitting conflict target in ON CONFLICT
  • Using DO NOTHING with UPDATE syntax
  • Missing EXCLUDED keyword for new values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes