QuestenaPractice that shows what to review next
Question 24

In PostgreSQL 18, a table is created as CREATE TABLE c3 (x int CHECK (x > 0)); and then INSERT INTO c3 VALUES (NULL); is run. What happens?

  1. The insert fails with a not-null violation
  2. The row is stored with x set to 0
  3. The insert fails with a check constraint violation
  4. The row is storedCorrect answer

Explanation

A check constraint is satisfied when the expression evaluates to true or to null, and NULL > 0 is null rather than false, so the row passes. Expecting a violation is the reason CHECK constraints are so often assumed to imply NOT NULL; enforcing that requires a separate not-null constraint.

Continue with this test

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