DIVIDE_TYPE()

All functions > MATH > DIVIDE_TYPE()

Same as DIVIDE, but preserves the type of the first argument.

Signatures

Type preserving division

Returns: Result of the division, with the dividend's type

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

With:

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

Signature notes:

  • Unlike DIVIDE, preserves the original data type of the dividend, including when the divisor is DECIMAL or approximate
  • For DECIMAL types, truncates toward zero at the dividend's scale
  • For integer types, truncates toward zero (7 // 2 is 3)
  • Returns NULL if either operand is NULL (NULL propagates before the zero-divisor check)
  • Division by zero raises an error only when both operands are non-NULL

Related operators

Examples

DIVIDE_TYPE(...)

FeatureQL
RETURN
    -- Function call
    f1 := DIVIDE_TYPE(10, 3)
;
Result
f1 BIGINT
3

.DIVIDE_TYPE(...) — chained

FeatureQL
RETURN
    -- Integer literal: parenthesize for `.DIVIDE_TYPE` on BIGINT
    f1 := (10).DIVIDE_TYPE(3),
    -- Decimal base: chain without extra parentheses; result rounds to the dividend scale (10 / 3 → 3.3 at scale 1)
    f2 := 10.0.DIVIDE_TYPE(3)
;
Result
f1 BIGINTf2 DECIMAL
33.3

Edge cases

FeatureQL
RETURN
    -- Exact division
    f1 := DIVIDE_TYPE(15, 5),
    -- Truncate toward zero
    f2 := DIVIDE_TYPE(7, 2),
    -- Negative dividend
    f3 := DIVIDE_TYPE(-9, 4)
;
Result
f1 BIGINTf2 BIGINTf3 BIGINT
33-2