Real, mathematical "modular" operation in Postgres?
2 answers
It seems that I will not find anything easier than:
CREATE OR REPLACE FUNCTION modulus(dividend numeric, divisor numeric) RETURNS numeric AS $$
DECLARE
result numeric;
BEGIN
divisor := ABS(divisor);
result := MOD(dividend, divisor);
IF result < 0 THEN
result := result + divisor;
END IF;
RETURN result;
END;
$$ LANGUAGE plpgsql;
0