Null Values in Spectre

Prior to version 7.0(14), most expressions that encountered null would return null, propagating the null all the way up the expression tree. For example, `1 + null` would result in null. Starting with Spectre 7.0(14), null can in many cases be treated as a normal value, like zero or the empty string. Therefore, in 7.0(14) and later, `1 + null` is 1. With this change, Spectre replicates the classic model behavior with nullable summaries.

There are many other differences, which this topic describes in detail, but the biggest changes are:

  • null is sometimes treated as zero or other normal values
  • null displays as blank in summary columns

Null indicates "no data". Here are some ways to get a null value in Spectre:

  • A blank field, that is a zero-length field, in a source file read by Spectre build
  • A value flagged as null using the nulls tag in Spectre build
  • A NULL value in an ODBC table read by Spectre build
  • The result of a summary expression in a dive window using multiple inputs, when the dimension value is not present in one of the inputs (that is, a multi-level multi-model)
  • The result of a summary expression when the working set is empty
  • The expression `null`
  • The expression `""`

You can check for null using the is_null() and notnull() functions, and use the coalesce() function to substitute alternative values for null.

Every null value has a type (integer, fixed100, double, string, date, period, or boolean), based on what the type of the value would be if it were not null. Null behaves differently depending on how it is used and what type it is:

  • For numeric types (integer, fixed100, and double), null is sometimes treated as zero, but there are exceptions depending on how it is used
  • For strings, null is the empty string and vice versa, for example, `"" == null` is true
  • For dates and periods, null is never treated as similar to a normal date or period, it is always considered special
  • For boolean types, null is treated as not true. This is notably different than being false, but in expressions that rely on a boolean result, such as if(), a null value corresponds to false.

See also: