-- -- Test the TRUNCATE TABLE command for cstore_fdw tables. -- -- Check that files for the automatically managed table exist in the -- cstore_fdw/{databaseoid} directory. SELECT count(*) FROM ( SELECT pg_ls_dir('cstore_fdw/' || databaseoid ) FROM ( SELECT oid::text databaseoid FROM pg_database WHERE datname = current_database() ) AS q1) AS q2; count ------- 0 (1 row) -- CREATE a cstore_fdw table, fill with some data -- CREATE FOREIGN TABLE cstore_truncate_test (a int, b int) SERVER cstore_server; CREATE FOREIGN TABLE cstore_truncate_test_second (a int, b int) SERVER cstore_server; CREATE TABLE cstore_truncate_test_regular (a int, b int); INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a; -- query rows SELECT * FROM cstore_truncate_test; a | b ----+---- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 (10 rows) TRUNCATE TABLE cstore_truncate_test; SELECT * FROM cstore_truncate_test; a | b ---+--- (0 rows) SELECT COUNT(*) from cstore_truncate_test; count ------- 0 (1 row) -- make sure data files still present SELECT count(*) FROM ( SELECT pg_ls_dir('cstore_fdw/' || databaseoid ) FROM ( SELECT oid::text databaseoid FROM pg_database WHERE datname = current_database() ) AS q1) AS q2; count ------- 4 (1 row) INSERT INTO cstore_truncate_test select a, a from generate_series(1, 10) a; INSERT INTO cstore_truncate_test_regular select a, a from generate_series(10, 20) a; INSERT INTO cstore_truncate_test_second select a, a from generate_series(20, 30) a; SELECT * from cstore_truncate_test; a | b ----+---- 1 | 1 2 | 2 3 | 3 4 | 4 5 | 5 6 | 6 7 | 7 8 | 8 9 | 9 10 | 10 (10 rows) SELECT * from cstore_truncate_test_second; a | b ----+---- 20 | 20 21 | 21 22 | 22 23 | 23 24 | 24 25 | 25 26 | 26 27 | 27 28 | 28 29 | 29 30 | 30 (11 rows) SELECT * from cstore_truncate_test_regular; a | b ----+---- 10 | 10 11 | 11 12 | 12 13 | 13 14 | 14 15 | 15 16 | 16 17 | 17 18 | 18 19 | 19 20 | 20 (11 rows) -- make sure multi truncate works TRUNCATE TABLE cstore_truncate_test, cstore_truncate_test_regular, cstore_truncate_test_second; SELECT * from cstore_truncate_test; a | b ---+--- (0 rows) SELECT * from cstore_truncate_test_second; a | b ---+--- (0 rows) SELECT * from cstore_truncate_test_regular; a | b ---+--- (0 rows) -- test if truncate on empty table works TRUNCATE TABLE cstore_truncate_test; SELECT * from cstore_truncate_test; a | b ---+--- (0 rows) DROP FOREIGN TABLE cstore_truncate_test, cstore_truncate_test_second; DROP TABLE cstore_truncate_test_regular;