3 -- Test the random function
5 -- count the number of tuples originally, should be 1000
6 SELECT count(*) FROM onek;
12 -- pick three random rows, they shouldn't match
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 (SELECT unique1 AS random
20 FROM onek ORDER BY random() LIMIT 1);
25 -- count roughly 1/10 of the tuples
26 SELECT count(*) AS random INTO RANDOM_TBL
27 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;
32 -- select again, the count should be different
33 INSERT INTO RANDOM_TBL (random)
35 FROM onek WHERE random() < 1.0/10;
36 -- select again, the count should be different
37 INSERT INTO RANDOM_TBL (random)
39 FROM onek WHERE random() < 1.0/10;
40 -- now test that they are different counts
41 SELECT random, count(random) FROM RANDOM_TBL
42 GROUP BY random HAVING count(random) > 3;
47 SELECT AVG(random) FROM RANDOM_TBL
48 HAVING AVG(random) NOT BETWEEN 80 AND 120;