Skip to main content
DB

Functions

NULL handling functions

7 NULL handling functions in NYXDB: names, aliases, signatures and behaviour.

7 functions. Names resolve case-insensitively; an alias binds the same function as its canonical name. Each entry gives the signatures, the behaviour and an example.

FunctionSummary
assume_not_nullRemoves a value’s nullable annotation after enforcing non-NULL validity.
coalesceReturns the earliest available non-NULL value from a compatible argument list.
if_nullSubstitutes a default only when the primary expression is SQL NULL.
is_not_nullRecognizes present SQL values, including zero and empty text.
is_nullDetects SQL absence without conflating it with JSON null or empty values.
is_zero_or_nullAccepts either numeric zero or SQL NULL as a true predicate result.
null_ifConverts a matching first value into SQL NULL while preserving unequal inputs.

assume_not_null

Removes a value’s nullable annotation after enforcing non-NULL validity.

assume_not_null(value:nullable(T)) -> T
Kindscalar
Signature classscalar/unary+generic
ReturnsT
AliasesassumeNotNull
StreamingContinuous — evaluated per row with no retained state.
DeterminismDeterministic — the same arguments always give the same result.
NULL handlingNULL is an error; otherwise strip nullability

Returns the original value through a nonnullable result descriptor when a proof or runtime check establishes its presence. An actual NULL raises INVALID_ARGUMENT rather than producing an arbitrary default. The operation changes nullability metadata without converting the underlying logical type.

Example

assume_not_null(7)
-- → 7

coalesce

Returns the earliest available non-NULL value from a compatible argument list.

coalesce(x1:T,x2:T,...) -> common_supertype(T...) nullable
Kindscalar
Signature classscalar/variadic+generic
Returnscommon_supertype(T...) nullable
Aliasesif_null
StreamingContinuous — evaluated per row with no retained state.
DeterminismDeterministic — the same arguments always give the same result.
NULL handlingfirst_non_NULL_argument;all_NULL_returns_NULL

Checks two through sixteen arguments in order and stops at the first value that is not SQL NULL. All-NULL input returns a typed NULL, and later expressions are masked after a value is found. Incompatible arity raises INVALID_ARGUMENT and a missing lossless common type raises TYPE_MISMATCH.

Example

coalesce(NULL, 7, 9)
-- → 7

if_null

Substitutes a default only when the primary expression is SQL NULL.

if_null(x:T,default:T) -> common_supertype(T,T)
Kindscalar
Signature classscalar/binary+generic
Returnscommon_supertype(T,T)
AliasesifNull
StreamingContinuous — evaluated per row with no retained state.
DeterminismDeterministic — the same arguments always give the same result.
NULL handlingNULL_x_selects_default;otherwise_x

Returns the first argument whenever it is present, evaluating the default only for NULL rows. A NULL default remains NULL if selected, and incompatible result types raise TYPE_MISMATCH. This binary operation preserves zero, false and empty strings as ordinary primary values.

Example

if_null(NULL, 12)
-- → 12

is_not_null

Recognizes present SQL values, including zero and empty text.

is_not_null(x:T) -> bool
Kindscalar
Signature classscalar/unary+generic
Returnsbool
AliasesisNotNull
StreamingContinuous — evaluated per row with no retained state.
DeterminismDeterministic — the same arguments always give the same result.
NULL handlingreturns_false_exactly_for_SQL_NULL

Returns false exactly for SQL NULL and true for every non-NULL value of a supported ledger type. It never returns NULL, and JSON null remains a present JSON value rather than SQL absence. Binding a nonvalue expression instead of one typed argument raises TYPE_MISMATCH.

Example

is_not_null('')
-- → true

is_null

Detects SQL absence without conflating it with JSON null or empty values.

is_null(x:T) -> bool
Kindscalar
Signature classscalar/unary+generic
Returnsbool
AliasesisNull
StreamingContinuous — evaluated per row with no retained state.
DeterminismDeterministic — the same arguments always give the same result.
NULL handlingreturns_true_exactly_for_SQL_NULL

Tests the SQL nullability flag independently of the value’s payload or logical type. The Boolean result is always present, including when the input is NULL. Empty arrays, empty strings and native JSON null return false; incompatible call shapes raise TYPE_MISMATCH.

Example

is_null(NULL)
-- → true

is_zero_or_null

Accepts either numeric zero or SQL NULL as a true predicate result.

is_zero_or_null(value:nullable(number)) -> bool
Kindscalar
Signature classscalar/unary
Returnsbool
StreamingContinuous — evaluated per row with no retained state.
DeterminismDeterministic — the same arguments always give the same result.
NULL handlingtrue for NULL or numeric zero; false otherwise

Returns true for a missing numeric value or for a value equal to zero, including floating negative zero. Every other number returns false and the predicate itself is never NULL. Nonnumeric input raises TYPE_MISMATCH; a floating NaN is not equal to zero.

Example

is_zero_or_null(0)
-- → true

null_if

Converts a matching first value into SQL NULL while preserving unequal inputs.

nullif(x:T,y:T) -> T nullable
Kindscalar
Signature classscalar/binary+generic
ReturnsT nullable
StreamingContinuous — evaluated per row with no retained state.
DeterminismDeterministic — the same arguments always give the same result.
NULL handlingequal_non_NULL_inputs_return_NULL;otherwise_x

Compares two values with SQL equality and returns NULL only when that comparison is true. If the second argument is NULL, a present first argument survives because the comparison is unknown. The input type must support equality or raise TYPE_MISMATCH; a NULL first argument remains NULL.

Example

nullif(8, 8)
-- → NULL

On this page