Documentation Correction For The generate_series Table-Valued Function
(1) By David Pratten (dpratten) on 2021-03-11 02:33:32 [source]
I recommend a small correction to the documentation for the generate_series Table-Valued Function (link) and provide the rationale below.
#1.1. Equivalent Recursive Common Table Expression The generate_series table can be simulated using a recursive common table expression (CTE). Include the following CTE at the beginning of your query:
WITH generate_series(rowNumber) as (select 0 union select rowNumber+1 from generate_series)
And then instead of
generate_series($start, $end, $step)
SELECT $start+rowNumber*$step FROM generate_series LIMIT ($end-$start)/$step+1
The common table expression works without having to load an extension. On the other hand, the extension is easier to program and faster.
The currently documented CTE needs to be refactored before a programmer can use it to replace the table-valued function.
All the best,