3

Is there any simple method to get a series:

0.01
0.02
0.03
...
...
...
0.97
0.98
0.99

like series generation from 1 to 99

SELECT *  FROM generate_series(1, 99)

2 Answers 2

4

Yes, it is quite easy:

Use :

SELECT a.n
FROM generate_series(0.01, 0.99,0.01) as a(n);

Working demo: http://sqlfiddle.com/#!17/9eecb/80581

0.01 - start of series  

0.99 - end of series  

0.01 - increment value from series start to series end
3

Another easy way:

select generate_series(1,99)::float/100;

The only trickiness here is the need to cast the integer to a float so you don't get integer division.

select generate_series(1.0,99)/100;

and

select generate_series(1,99)/100.0;

also work but for some reason display with lots of trailing zeros.

2
  • 1
    In this instance I would use * 0.01 instead of either / 100 or / 100.0.
    – Andriy M
    Sep 3, 2021 at 10:57
  • Interesting the difference between SELECT FROM GENERATE_SERIES(... and SELECT GENERATE_SERIES (... ~ 2 x! Might be of interest if you're generating millions of values...
    – Vérace
    Sep 3, 2021 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.