QuestenaPractice that shows what to review next
Question 25

In PostgreSQL 18, a table is created as CREATE TABLE c4 (a int, b int, UNIQUE (a, b)); and the row (1, NULL) is inserted twice. What happens?

  1. Both rows are storedCorrect answer
  2. The second insert fails with a unique violation
  3. The second insert fails only when every column of the key is null
  4. It raises an error, because a multi-column UNIQUE key may not contain nulls

Explanation

A multi-column unique constraint is violated only when the values of all constrained columns are equal, and a null in b is not equal to another null, so a single nullable column is enough to defeat the constraint even though a is duplicated. The constraint is otherwise active: inserting (1, 5) twice is rejected.

Continue with this test

Start practice
Question 25: In PostgreSQL 18, a table is created as CREATE TABLE c4 (a… · SQL: NULL, Joins and Aggregates · Questena