Repository navigation
time: propagate NULL instead of raising - #169
Merged
Merged
Conversation
Argument-taking time functions validated types with a positive gate and
rejected everything else, so a NULL argument raised an error rather than
yielding NULL. Only time_parse propagated. Unguarded calls over
null-extended expressions therefore aborted the statement: outer joins,
aggregates, ORDER BY, and expression indexes on a nullable column.
Check every argument for NULL ahead of the type gate. The scan precedes
type validation, so the result does not depend on argument order:
time_add(NULL, 'bad') and time_add('bad', NULL) both return NULL. Invalid
non-NULL arguments still error.
A CHECK constraint is satisfied by a NULL result, so
check (time_get_year(at) >= 2000) no longer rejects a NULL value; NOT NULL
requires one. Generated columns and expression indexes likewise accept rows
they previously refused.
nalgeon
requested changes
Sep 4, 2026
nalgeon
requested changes
Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
All argument-taking
time_*functions return NULL if any argument is NULL, matching whattime_parsealready did. NULL is detected before type validation, so it takes precedence over an invalid argument in another position: bothtime_add(NULL, 'bad')andtime_add('bad', NULL)return NULL. When no argument is NULL, results and type errors are unchanged.Why
The functions were unusable over nullable expressions:
Wrapping the result in
coalescecannot catch the error, and filtering on the result still evaluates it.CASEworks, but has to be repeated at every call site.Indexes have no workaround.
create index on events(time_get_year(at))fails if the table holds a NULL row, and once created it rejects later NULL inserts, so an index added for performance refuses data.Compatibility
No previously successful call changes. Calls containing NULL that previously raised now return NULL.
Schema-level behavior does change. CHECK constraints, generated columns, and expression indexes accept rows containing NULL where evaluation previously aborted the write:
I think that is right for a nullable column. The CHECK says present values must satisfy the predicate, while the old behavior also effectively rejected NULL, which
check (x >= 2000)on a nullable integer never did.NOT NULLremains the way to require a value.