Re: Add generate_series(numeric, numeric) - Mailing list pgsql-hackers

From Ali Akbar
Subject Re: Add generate_series(numeric, numeric)
Date
Msg-id CACQjQLraP1njx=T_LY4jLimRwQGGuT3W9JG7G1N-P5JpUwh8LA@mail.gmail.com
Whole thread Raw
In response to Re: Add generate_series(numeric, numeric)  (Michael Paquier <michael.paquier@gmail.com>)
Responses Re: Add generate_series(numeric, numeric)
List pgsql-hackers
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:

 numeric
---------
      -9
      -8
      -7
      -6
      -5
      -4
      -3
      -2
      -1
       0
       1
       2
       3
       4
       5
       6
       7
       8
       9
(19 rows)



Regards,
--
Ali Akbar
Attachment

pgsql-hackers by date:

Previous
From: Marti Raudsepp
Date:
Subject: Re: CREATE IF NOT EXISTS INDEX
Next
From: Emre Hasegeli
Date:
Subject: Re: KNN-GiST with recheck