1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. In INSERT INTO t VALUES (...) ON CONFLICT (id) DO UPDATE…

Added 30 Nov -0001

In INSERT INTO t VALUES (...) ON CONFLICT (id) DO UPDATE SET n = excluded.n, what does excluded refer to?

  1. A temporary table holding the rejected rows for a later retry batch
  2. The set of columns left out of the conflict target index definition
  3. The row proposed for insertion, whose values feed the update expression Correct answer
  4. The row already stored, whose values are skipped by the conflict clause

Correct answer

C. The row proposed for insertion, whose values feed the update expression

20 views

MCQSEXAM

Explanation

In PostgreSQL's upsert, excluded is the pseudo-table holding the row the INSERT tried to add, so SET n = excluded.n copies the incoming value over the stored one. The stored row can also be referenced by the target table's own name to compute arithmetic such as n = t.n + excluded.n. Without a conflict target, ON CONFLICT DO NOTHING applies to any unique violation.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs