QuestenaPractice that shows what to review next
Question 22

In PostgreSQL 18, a table is created as CREATE TABLE c1 (x int UNIQUE); and two rows are then inserted, both with x set to NULL. What happens?

  1. The second insert fails with a unique violation
  2. Both rows are storedCorrect answer
  3. The CREATE TABLE fails, because a UNIQUE column must also be NOT NULL
  4. The second insert is accepted but silently discarded

Explanation

By default two null values are not considered equal for uniqueness, so a UNIQUE column can hold any number of null rows. This is why a nullable UNIQUE column is not a safe way to enforce at most one row per entity, and why this default is worth stating explicitly in a schema.

Continue with this test

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