On Tue, 16 Jun 2020 at 10:09, Juan José Santamaría Flecha <juanjo.santamaria@gmail.com> wrote: > > It is defined as NaN (or undefined), which is not in the realm of integer numbers. You might get a clear idea of the logic from [1], where they also make a case for the error being ERRCODE_DIVISION_BY_ZERO. > > [1] http://mathforum.org/library/drmath/view/60851.html >
Hmm, I think ERRCODE_DIVISION_BY_ZERO should probably be reserved for actual division functions.
With [1], we could return 'Infinity', which would be more correct from a mathematical point of view, and might be preferable to erroring-out in some contexts.
Returning division-by-zero would be confusing for the user.
I think that out-of-range would be a reasonable solution for "FUNCTION factorial(integer) RETURNS integer", because it could only return an integer when the input is a positive integer, but for "FUNCTION factorial(integer) RETURNS numeric" the returned value should be 'NaN' without error.