I feel like I'm missing something obvious. I am trying to check the distribution of random() . Here is the table:
create table test ( id int, random_float float, random_int int );
Here is what I want to do:
truncate table test; insert into test (id) values (generate_series(1,1000)); update test set random_float = random() * 10 + 1; update test set random_int = trunc(random_float); select random_int, count(random_int) as Count, cast( count(random_int) / max(id) as float) as Percent from test group by random_int order by random_int;
However, the Percentage column returns zero for each record. I tried to use it as a float, as a decimal, I tried to change the random_int column to decimal, and not to integer, always to the same result.
Here is the fiddle.
Any insight on what I'm doing wrong?
source share