Always forbid NULL values in array elements
Currently, when defining an array column in the Contember schema using the .list() method, the .notNull() constraint applies only to the column itself. This means that while the column cannot be NULL, the array may still contain NULL elements. For example:
someValues = c.stringColumn().list().notNull()
allows:
- An empty array:
[] - Arrays with
NULLelements, e.g.,[NULL],[value, NULL]
Proposal
We propose to change the behavior for array columns so that NULL values in the array elements are always forbidden. This change is independent of the .notNull() constraint on the column, which will continue to only ensure that the column itself is non-NULL.
Under this proposal:
-
Column Constraint (
.notNull()):
Prevents the entire column from beingNULL. -
Element Constraint (Always Active for Arrays):
Enforces that noNULLvalues can exist within the array. This could be implemented with a check constraint similar to:CHECK (array_position(foo, null) IS NULL)
Request for Feedback
- Do you agree with the approach of always forbidding
NULLvalues in array elements? - Can you identify any use cases or scenarios where having
NULLelements in an array would be beneficial?