1 CREATE EXTENSION tsm_system_rows;
3 CREATE TABLE test_tablesample (id int, name text);
4 INSERT INTO test_tablesample SELECT i, repeat(i::text, 1000)
5 FROM generate_series(0, 30) s(i);
6 ANALYZE test_tablesample;
8 SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (0);
9 SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (1);
10 SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (10);
11 SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (100);
13 -- bad parameters should get through planning, but not execution:
15 SELECT id FROM test_tablesample TABLESAMPLE system_rows (-1);
17 SELECT id FROM test_tablesample TABLESAMPLE system_rows (-1);
19 -- fail, this method is not repeatable:
20 SELECT * FROM test_tablesample TABLESAMPLE system_rows (10) REPEATABLE (0);
22 -- but a join should be allowed:
25 (VALUES (0),(10),(100)) v(nrows),
26 LATERAL (SELECT count(*) FROM test_tablesample
27 TABLESAMPLE system_rows (nrows)) ss;
30 (VALUES (0),(10),(100)) v(nrows),
31 LATERAL (SELECT count(*) FROM test_tablesample
32 TABLESAMPLE system_rows (nrows)) ss;
35 SELECT count(*) FROM test_tablesample TABLESAMPLE system_rows (20);
39 DROP EXTENSION tsm_system_rows; -- fail, view depends on extension