QuestenaՎարժանք, որը ցույց է տալիս՝ ինչ կրկնել հաջորդիվ
Հարց 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 storedՃիշտ պատասխան
  3. The CREATE TABLE fails, because a UNIQUE column must also be NOT NULL
  4. The second insert is accepted but silently discarded

Բացատրություն

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.

Շարունակեք այս թեստով

Սկսել վարժանքը
Հարց 22: In PostgreSQL 18, a table is created as CREATE TABLE c1 (x… · SQL: NULL, Joins and Aggregates · Questena