Thanks for the review. Attached the formatted patch according to your suggestion.
- numeric datatype is large, but there are limitations. According to doc, the limit is: up to 131072 digits before the decimal point; up to 16383 digits after the decimal point. How can we check if the next step overflows? As a comparison, in int.c, generate_series_step_int4 checks if its overflows, and stop the next call by setting step to 0. Should we do that?
Yes we should.
how can we check the overflow after add_var? (in int.c, the code checks for integer calculation overflow, that wraps the result to negative value)
in numeric.sql regression test, i've added this query: select (i / (10::numeric ^ 131071))::numeric(1,0) from generate_series(-9*(10::numeric ^ 131071), 9*(10::numeric ^ 131071), (10::numeric ^ 131071)) as a(i);
Because the doc notes that the maximum numeric digit before decimal point is 131072, i hope this query covers the overflow case (in the last value it will generate, if we add 9 x 10^13071 with 10^13071, add_var will overflows). But in my tests, that isn't the case. The code works without any error and returns the correct rows: