2002-08-22 06:51:06 +02:00
|
|
|
-- Test basic TRUNCATE functionality.
|
|
|
|
CREATE TABLE truncate_a (col1 integer primary key);
|
2003-07-19 22:20:53 +02:00
|
|
|
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "truncate_a_pkey" for table "truncate_a"
|
2002-08-22 06:51:06 +02:00
|
|
|
INSERT INTO truncate_a VALUES (1);
|
|
|
|
INSERT INTO truncate_a VALUES (2);
|
|
|
|
SELECT * FROM truncate_a;
|
|
|
|
col1
|
|
|
|
------
|
|
|
|
1
|
|
|
|
2
|
|
|
|
(2 rows)
|
|
|
|
|
2002-11-23 05:05:52 +01:00
|
|
|
-- Roll truncate back
|
|
|
|
BEGIN;
|
2002-08-22 06:51:06 +02:00
|
|
|
TRUNCATE truncate_a;
|
2002-11-23 05:05:52 +01:00
|
|
|
ROLLBACK;
|
|
|
|
SELECT * FROM truncate_a;
|
|
|
|
col1
|
|
|
|
------
|
|
|
|
1
|
|
|
|
2
|
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
-- Commit the truncate this time
|
|
|
|
BEGIN;
|
|
|
|
TRUNCATE truncate_a;
|
|
|
|
COMMIT;
|
2002-08-22 06:51:06 +02:00
|
|
|
SELECT * FROM truncate_a;
|
|
|
|
col1
|
|
|
|
------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
-- Test foreign constraint check
|
|
|
|
CREATE TABLE truncate_b(col1 integer references truncate_a);
|
|
|
|
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
|
|
|
INSERT INTO truncate_a VALUES (1);
|
|
|
|
SELECT * FROM truncate_a;
|
|
|
|
col1
|
|
|
|
------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
TRUNCATE truncate_a;
|
2002-08-22 16:23:36 +02:00
|
|
|
ERROR: TRUNCATE cannot be used as table truncate_b references this one via foreign key constraint $1
|
2002-08-22 06:51:06 +02:00
|
|
|
SELECT * FROM truncate_a;
|
|
|
|
col1
|
|
|
|
------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
DROP TABLE truncate_b;
|
|
|
|
DROP TABLE truncate_a;
|