In Ruby:
x
-2 % 24
=> 22
In Postgres:
SELECT -2 % 24;
?column?
----------
-2
SELECT mod(-2,24);
mod
-----
-2
I can easily write one myself, but I’m curious whether Postgres has a real modulus operation, as opposed to remainder after division.
Advertisement
Answer
SELECT MOD(24 + MOD(-2, 24), 24);
will return 22 instead of -2