3.6. Vendor Math Functions

All other math functions are vendor extensions, but you can plan on several common ones in most SQL implementations. They are implemented under assorted names, and often with slightly different functionality.

3.6.1. Number Theory Operators

(x MOD m) or MOD(x, m) is the function that performs modulo or remainder arithmetic. This is tricky when the values of x and m are not cardinals (i.e., positive, nonzero integers). Experiment and find out how your package handles negative numbers and decimal places.

In September 1996, Len Gallagher proposed an amendment for the MOD function in SQL3. Originally, the working draft defined MOD(x, m) only for positive values of both m and x, and left the result to be implementation-dependent ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.