VeloDB Cloud
SQL Reference
SQL Functions
Scalar Functions
Numeric Functions
PMOD

PMOD

Description

Returns the smallest positive solution of the modulo operation x mod y within the modular system, which is obtained by calculating (x % y + y) % y.

Syntax

PMOD(<x> , <y>)

Parameters

ParameterDescription
<x>Dividend
<y>Divisor should not be 0

Return value

Returns an integer or a floating-point number. Special cases:

  • If x = 0, returns 0.
  • If x is NULL or y is NULL, returns NULL.

Example

SELECT PMOD(13,5);
+-------------+
| pmod(13, 5) |
+-------------+
|           3 |
+-------------+
SELECT PMOD(-13,5);
+--------------+
| pmod(-13, 5) |
+--------------+
|            2 |
+--------------+
SELECT PMOD(0,-12);
+--------------+
| pmod(0, -12) |
+--------------+
|            0 |
+--------------+
SELECT PMOD(0,null);
+-------------------------------+
| pmod(cast(0 as DOUBLE), NULL) |
+-------------------------------+
|                          NULL |
+-------------------------------+