Skip to main content

Nullity and Uniqueness

Validations to check for the presence of null values and the uniqueness of values across rows.


Column must not have null values

Every row in the column must have a non-null value.

Use this when you want to enforce that a column is fully populated — for example, an order_id or email column that must always have a value.

Parameters

NameTypeRequiredDescription
ColumnColumnThe column to validate.

Example

order_idcustomer_emailamount
1alice@example.com120
2NULL85
3bob@example.com200
Example 1Example 2
Columncustomer_emailorder_id
Result❌ Fails✅ Passes
ReasonRow 2 has a NULL value in customer_emailNo null values found in order_id

Column values must be null

Every row in the column must have a null value.

Use this when you want to assert that a column is intentionally empty — for example, a deleted_at column for records that have not been soft-deleted.

Parameters

NameTypeRequiredDescription
ColumnColumnThe column to validate.

Example

order_iddeleted_atstatus
1NULLactive
2NULLactive
3NULLactive
Example 1Example 2
Columnstatusdeleted_at
Result❌ Fails✅ Passes
Reasonactive in row 1 is not nullAll rows in deleted_at are NULL

Column values must be unique

Every value in the column must be unique across all rows.

Use this when you want to enforce that a column acts as a natural key — for example, order_id, user_id, or any identifier column.

Parameters

NameTypeRequiredDescription
ColumnColumnThe column to validate.

Example

order_idproduct_idquantity
1001423
1002171
1003422
Example 1Example 2
Columnproduct_idorder_id
Result❌ Fails✅ Passes
Reason42 appears in rows 1 and 3All values in order_id are unique

Set of column values must be unique

The combination of values across two or more columns must be unique for every row.

Use this when no single column is unique on its own, but the combination of columns should be — for example, (user_id, date) in a daily activity table where each user should have at most one record per day.

Parameters

NameTypeRequiredDescription
Column listSetTwo or more column names, comma-separated. For example: user_id, date

Example

user_iddatesessions
1012026-04-013
1012026-04-021
1022026-04-015
1012026-04-012
Example 1Example 2
Column listuser_id, dateuser_id, sessions
Result❌ Fails✅ Passes
ReasonThe combination (101, 2026-04-01) appears in rows 1 and 4All combinations of user_id and sessions are unique

Column values must be unique in the same row

The values across the specified columns must be unique within each individual row.

Use this when you need to ensure that no two columns in the same row share the same value — for example, a survey table where first_choice and second_choice must always be different options.

Parameters

NameTypeRequiredDescription
Column listSetTwo or more column names, comma-separated. For example: first_choice, second_choice

Example

response_idfirst_choicesecond_choicethird_choice
1ABC
2AAC
3BCA
Example 1Example 2
Column listfirst_choice, second_choicefirst_choice, third_choice
Result❌ Fails✅ Passes
ReasonRow 2 has the same value A in both first_choice and second_choiceNo row shares the same value across first_choice and third_choice