% [remainder]

All functions > MATH > % [remainder]

Returns the remainder after dividing the left-hand number by the right-hand number.

Syntax

left % right  ·  MODULO(left, right)  ·  MOD(left, right)

Function form

Modulo: Remainder of the division

MODULO(dividend: T, divisor: T) → T
sql
ParameterTypeRequiredDescription
dividendTYesNumber to be divided
divisorTYesNumber to divide by

With:

  • T : Custom types: TINYINT | SMALLINT | INT | BIGINT | DECIMAL

  • Both arguments must be of the same type (integer or DECIMAL)

  • Sign of the result matches the sign of the dividend

  • Returns NULL if either operand is NULL

  • Division by zero raises an error

Aliases: MOD

Notes

  • Supported for integer and DECIMAL types; both operands must be the same type
  • The result has the same type as the operands; its sign follows the dividend
  • Returns NULL if either operand is NULL
  • Division by zero is an error

Examples

Modulo - remainder

FeatureQL
RETURN
    -- Basic modulo
    f1 := 10 % 3,
    -- Non-zero remainder
    f2 := 15 % 4
;
Result
f1 BIGINTf2 BIGINT
13

Modulo - edge cases

FeatureQL
RETURN
    -- Sign follows dividend
    f1 := -10 % 3,
    -- No remainder
    f2 := 7 % 7
;
Result
f1 BIGINTf2 BIGINT
-10

MODULO(...)

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

.MODULO(...) — chained

FeatureQL
RETURN
    -- Integer literal: parenthesize for `.MODULO` on BIGINT
    f1 := (10).MODULO(3),
    -- Decimal base: chain without extra parentheses
    f2 := 10.0.MODULO(3)
;
Result
f1 BIGINTf2 DECIMAL
11.0

MODULO — Edge cases

FeatureQL
RETURN
    -- Another remainder
    f1 := MODULO(15, 4),
    -- No remainder
    f2 := MODULO(7, 7),
    -- Negative dividend
    f3 := MODULO(-10, 3)
;
Result
f1 BIGINTf2 BIGINTf3 BIGINT
30-1