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)
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communityYes, 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
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.
* 0.01
instead of either / 100
or / 100.0
.
SELECT FROM GENERATE_SERIES(...
and SELECT GENERATE_SERIES (...
~ 2 x! Might be of interest if you're generating millions of values...