TRY_DIVIDE()

All functions > MATH > TRY_DIVIDE()

Same as DIVIDE, but returns NULL if the divisor is zero.

Signatures

Safe numeric division

Returns: Result of the division, or NULL if the divisor is zero

TRY_DIVIDE(dividend: T, divisor: U) → DOUBLE
sql
ParameterTypeRequiredDescription
dividendTYesNumber to be divided
divisorUYesNumber to divide by

With:

  • T : Any numeric type
  • U : Any numeric type

Signature notes:

  • Both arguments are cast to DOUBLE before division
  • Returns NULL if either operand is NULL or if the divisor is zero
  • Result is always a DOUBLE, even for integer inputs
  • Safe alternative to DIVIDE when the divisor may be zero

Examples

Division by zero

FeatureQL
SELECT
    f1 := TRY_DIVIDE(10E0, 3E0), -- Division with remainder
    f2 := TRY_DIVIDE(15E0, 5E0), -- Exact division
    f3 := TRY_DIVIDE(-8E0, 4E0) -- Negative division
;
Result
f1 VARCHARf2 VARCHARf3 VARCHAR
3.33333333333333353.0-2.0

Last update at: 2026/05/26 17:22:09