SET search_path TO truncate_cascade_tests_schema; -- Hide detail of truncate error because it might either reference -- table_with_fk_1 or table_with_fk_2 in the error message. \set VERBOSITY TERSE -- Test truncate error on table with dependencies TRUNCATE table_with_pk; ERROR: cannot truncate a table referenced in a foreign key constraint \set VERBOSITY DEFAULT -- Test truncate rollback on table with dependencies SELECT COUNT(*) FROM table_with_fk_1; count --------------------------------------------------------------------- 10 (1 row) SELECT COUNT(*) FROM table_with_fk_2; count --------------------------------------------------------------------- 10 (1 row) BEGIN; TRUNCATE table_with_pk CASCADE; SELECT COUNT(*) FROM table_with_fk_1; count --------------------------------------------------------------------- 0 (1 row) SELECT COUNT(*) FROM table_with_fk_2; count --------------------------------------------------------------------- 0 (1 row) ROLLBACK; SELECT COUNT(*) FROM table_with_fk_1; count --------------------------------------------------------------------- 10 (1 row) SELECT COUNT(*) FROM table_with_fk_2; count --------------------------------------------------------------------- 10 (1 row) -- Test truncate on table with dependencies SELECT COUNT(*) FROM table_with_pk; count --------------------------------------------------------------------- 10 (1 row) SELECT COUNT(*) FROM table_with_fk_1; count --------------------------------------------------------------------- 10 (1 row) SELECT COUNT(*) FROM table_with_fk_2; count --------------------------------------------------------------------- 10 (1 row) TRUNCATE table_with_pk CASCADE; SELECT COUNT(*) FROM table_with_pk; count --------------------------------------------------------------------- 0 (1 row) SELECT COUNT(*) FROM table_with_fk_1; count --------------------------------------------------------------------- 0 (1 row) SELECT COUNT(*) FROM table_with_fk_2; count --------------------------------------------------------------------- 0 (1 row)