3 -- Test the random function
6 -- count the number of tuples originally, should be 1000
7 SELECT count(*) FROM onek;
9 -- pick three random rows, they shouldn't match
10 (SELECT unique1 AS random
11 FROM onek ORDER BY random() LIMIT 1)
13 (SELECT unique1 AS random
14 FROM onek ORDER BY random() LIMIT 1)
16 (SELECT unique1 AS random
17 FROM onek ORDER BY random() LIMIT 1);
19 -- count roughly 1/10 of the tuples
20 SELECT count(*) AS random INTO RANDOM_TBL
21 FROM onek WHERE random() < 1.0/10;
23 -- select again, the count should be different
24 INSERT INTO RANDOM_TBL (random)
26 FROM onek WHERE random() < 1.0/10;
28 -- select again, the count should be different
29 INSERT INTO RANDOM_TBL (random)
31 FROM onek WHERE random() < 1.0/10;
33 -- select again, the count should be different
34 INSERT INTO RANDOM_TBL (random)
36 FROM onek WHERE random() < 1.0/10;
38 -- now test that they are different counts
39 SELECT random, count(random) FROM RANDOM_TBL
40 GROUP BY random HAVING count(random) > 3;
42 SELECT AVG(random) FROM RANDOM_TBL
43 HAVING AVG(random) NOT BETWEEN 80 AND 120;