Bird
0
0

What will be the output of this query?

medium📝 query result Q5 of 15
PostgreSQL - Set Operations and Advanced Queries
What will be the output of this query?
INSERT INTO employees(id, name, salary) VALUES (1, 'Alice', 5000) ON CONFLICT (id) DO UPDATE SET salary = EXCLUDED.salary + 1000 RETURNING salary;

Assuming an employee with id=1 and salary=4000 already exists.
A6000
B5000
C4000
DError due to invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Identify the conflict and update logic

    The conflict is on id=1. The update sets salary to EXCLUDED.salary + 1000.
  2. Step 2: Calculate the new salary

    EXCLUDED.salary is 5000, so 5000 + 1000 = 6000 is the new salary.
  3. Final Answer:

    6000 -> Option A
  4. Quick Check:

    Salary after update = 6000 [OK]
Quick Trick: EXCLUDED refers to new insert values, not existing row [OK]
Common Mistakes:
  • Adding 1000 to existing salary instead of EXCLUDED.salary
  • Confusing EXCLUDED with existing table values
  • Syntax errors in ON CONFLICT clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes