|
2 | 2 | -- RANDOM
|
3 | 3 | -- Test the random function
|
4 | 4 | --
|
5 |
| --- count the number of tuples originally |
| 5 | +-- count the number of tuples originally, should be 1000 |
6 | 6 | SELECT count(*) FROM onek;
|
7 | 7 | count
|
8 | 8 | -------
|
9 | 9 | 1000
|
10 | 10 | (1 row)
|
11 | 11 |
|
12 |
| --- select roughly 1/10 of the tuples |
13 |
| --- Assume that the "onek" table has 1000 tuples |
14 |
| --- and try to bracket the correct number so we |
15 |
| --- have a regression test which can pass/fail |
16 |
| --- - thomas 1998-08-17 |
| 12 | +-- pick three random rows, they shouldn't match |
| 13 | +(SELECT unique1 AS random |
| 14 | + FROM onek ORDER BY random() LIMIT 1) |
| 15 | +INTERSECT |
| 16 | +(SELECT unique1 AS random |
| 17 | + FROM onek ORDER BY random() LIMIT 1) |
| 18 | +INTERSECT |
| 19 | +(SELECT unique1 AS random |
| 20 | + FROM onek ORDER BY random() LIMIT 1); |
| 21 | + random |
| 22 | +-------- |
| 23 | +(0 rows) |
| 24 | + |
| 25 | +-- count roughly 1/10 of the tuples |
17 | 26 | SELECT count(*) AS random INTO RANDOM_TBL
|
18 | 27 | FROM onek WHERE random() < 1.0/10;
|
19 | 28 | -- select again, the count should be different
|
20 | 29 | INSERT INTO RANDOM_TBL (random)
|
21 | 30 | SELECT count(*)
|
22 | 31 | FROM onek WHERE random() < 1.0/10;
|
23 |
| --- now test the results for randomness in the correct range |
| 32 | +-- select again, the count should be different |
| 33 | +INSERT INTO RANDOM_TBL (random) |
| 34 | + SELECT count(*) |
| 35 | + FROM onek WHERE random() < 1.0/10; |
| 36 | +-- select again, the count should be different |
| 37 | +INSERT INTO RANDOM_TBL (random) |
| 38 | + SELECT count(*) |
| 39 | + FROM onek WHERE random() < 1.0/10; |
| 40 | +-- now test that they are different counts |
24 | 41 | SELECT random, count(random) FROM RANDOM_TBL
|
25 |
| - GROUP BY random HAVING count(random) > 1; |
| 42 | + GROUP BY random HAVING count(random) > 3; |
26 | 43 | random | count
|
27 | 44 | --------+-------
|
28 | 45 | (0 rows)
|
29 | 46 |
|
30 |
| -SELECT random FROM RANDOM_TBL |
31 |
| - WHERE random NOT BETWEEN 80 AND 120; |
32 |
| - random |
33 |
| --------- |
| 47 | +SELECT AVG(random) FROM RANDOM_TBL |
| 48 | + HAVING AVG(random) NOT BETWEEN 80 AND 120; |
| 49 | + avg |
| 50 | +----- |
34 | 51 | (0 rows)
|
35 | 52 |
|
0 commit comments