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

From Andrew Gierth
Subject Re: Add generate_series(numeric, numeric)
Date
Msg-id 87mw6ppraf.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to Re: Add generate_series(numeric, numeric)  (Fujii Masao <masao.fujii@gmail.com>)
Responses Re: Add generate_series(numeric, numeric)  (Ali Akbar <the.apaan@gmail.com>)
Re: Add generate_series(numeric, numeric)  (Fujii Masao <masao.fujii@gmail.com>)
List pgsql-hackers
>>>>> "Fujii" == Fujii Masao <masao.fujii@gmail.com> writes:

 Fujii> Pushed.

Bug found:

regression=# select count(*) from generate_series(1::numeric,10) v, generate_series(1,v) w;
 count
-------
 99990
(1 row)

regression=# select count(*) from generate_series(1::numeric,10) v, generate_series(1,v+0) w;
 count
-------
    55
(1 row)

The error is in the use of PG_GETARG_NUMERIC and init_var_from_num
when setting up the multi-call state; init_var_from_num points at the
original num's digits rather than copying them, but start_num and
stop_num have just been (potentially) detoasted in the per-call
context, in which case the storage will have been freed by the next
call.

Obviously this could also be fixed by not detoasting the input until
after switching to the multi-call context, but it looks to me like
that would be unnecessarily complex.

Suggested patch attached.

(Is it also worth putting an explicit warning about this kind of thing
in the SRF docs?)

--
Andrew (irc:RhodiumToad)


Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: [REVIEW] Re: Fix xpath() to return namespace definitions
Next
From: Michael Paquier
Date:
Subject: Re: alter user/role CURRENT_USER