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

Is there any simple method to get a series

One method

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

Working example

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.

1
  • 2
    In this instance I would use * 0.01 instead of either / 100 or / 100.0.
    – Andriy M
    Sep 3, 2021 at 10:57

Your Answer

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

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