]> granicus.if.org Git - postgresql/blob - src/test/regress/expected/truncate.out
# Disallow TRUNCATE on tables that are involved in referential
[postgresql] / src / test / regress / expected / truncate.out
1 -- Test basic TRUNCATE functionality.
2 CREATE TABLE truncate_a (col1 integer primary key);
3 NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 'truncate_a_pkey' for table 'truncate_a'
4 INSERT INTO truncate_a VALUES (1);
5 INSERT INTO truncate_a VALUES (2);
6 SELECT * FROM truncate_a;
7  col1 
8 ------
9     1
10     2
11 (2 rows)
12
13 TRUNCATE truncate_a;
14 SELECT * FROM truncate_a;
15  col1 
16 ------
17 (0 rows)
18
19 -- Test foreign constraint check
20 CREATE TABLE truncate_b(col1 integer references truncate_a);
21 NOTICE:  CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
22 INSERT INTO truncate_a VALUES (1);
23 SELECT * FROM truncate_a;
24  col1 
25 ------
26     1
27 (1 row)
28
29 TRUNCATE truncate_a;
30 ERROR:  TRUNCATE cannot be used as other tables reference this one via foreign key constraint $1
31 SELECT * FROM truncate_a;
32  col1 
33 ------
34     1
35 (1 row)
36
37 DROP TABLE truncate_b;
38 DROP TABLE truncate_a;