MOD()

Documentation

VoltDB Home » Documentation » Using VoltDB

MOD()

MOD() — Returns the result of a modulo operation.

Synopsis

MOD( dividend, divisor )

Description

The MOD() function performs a modulo operation. That is, it divides one value, the dividend, by another value, the divisor, and returns the remainder of the division operation as a new integer value. The sign of the result, whether positive or negative, matches the sign of the first argument, the dividend.

Both the dividend and the divisor must either both be integer values or both be DECIMAL values and the divisor must not be zero. Use of mixed input datatypes or a divisor of zero will result in a runtime error. When using DECIMAL input values, the result is the integer portion of the remainder. In other words, the decimal result is truncated and returned as an integer using the following formula:

MOD(a,b) = a - INT(a/b) * b

Example

The following example uses the HOUR() and MOD() functions to return the hour of a timestamp in 12 hour format

SELECT event, 
       MOD(HOUR(eventtime)+11, 12)+1,
       CASE WHEN HOUR(eventtime)/12 < 1
          THEN 'AM'
          ELSE 'PM'
       END
   FROM schedule ORDER BY 3, 2;