November 23rd, 2014 by depesz | Tags: , , , | No comments »
Did it help? If yes - maybe you can help me?

On 11th of November, Fujii Masao committed patch:

Add generate_series(numeric, numeric).
 
Платон Малюгин
Reviewed by Michael Paquier, Ali Akbar and Marti Raudsepp

generate_series() is one of the most commonly used functions – at least for me.

If you're not familiar with it – it generates set of rows with values based on arguments. For example:

$ select generate_series(1,10) i;
 i  
----
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
(10 rows)

Or:

select generate_series('2014-01-01 00:00:00'::timestamp, now(), '65 days 7 hours 13 minutes 2 seconds'::interval);
    generate_series     
------------------------
 2014-01-01 00:00:00+01
 2014-03-07 07:13:02+01
 2014-05-11 14:26:04+02
 2014-07-15 21:39:06+02
 2014-09-19 04:52:08+02
(5 rows)

So far we had versions of the functions working on integers, and timestamps (both with time zone and without). Now we got also version that works on numeric values.

Technically, we were able to numerics from generate_series by doing casts and possibly some calculations, now it's simpler than ever:

select generate_series(10.1, 15.1);
 generate_series 
-----------------
            10.1
            11.1
            12.1
            13.1
            14.1
            15.1
(6 rows)

Or the three-argument version:

select generate_series(10.1, 15.1, 2.2356);
 generate_series 
-----------------
            10.1
         12.3356
         14.5712
(3 rows)

Cool. That will definitely be helpful. Thanks guys.

Leave a comment