UNSAFE_NATIVE()

All functions > DATE AND TIME > UNSAFE_NATIVE()

Returns the value an INTERVAL is stored as on the backend, instead of its canonical text.

Signatures

Returns: months * 10^20 + microseconds

UNSAFE_NATIVE(interval: INTERVAL) → DECIMAL(38, 0)
sql
ParameterTypeRequiredDescription
intervalINTERVALYesAn INTERVAL value

Notes

  • An INTERVAL is two parts, months and microseconds (a day is 24 hours). Every backend stores it as one DECIMAL(38, 0): months * 10^20 + microseconds
  • Query results show an INTERVAL as canonical ISO 8601 text (P1M2DT3H); UNSAFE_NATIVE() returns the stored number instead
  • Use it to write an interval to a table or pass it to an engine function; the number is the same on every backend
  • Comparing the numbers orders intervals by months first, then microseconds, like comparing the intervals

Examples

FeatureQL
RETURN
    -- A day is 86 400 000 000 microseconds and no months
    f1 := UNSAFE_NATIVE(INTERVAL '1 day')
;
Result
f1 DECIMAL
86400000000