summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorBruce Momjian2002-08-22 04:51:06 +0000
committerBruce Momjian2002-08-22 04:51:06 +0000
commit47b37a6bfaa073076c8607cdd4f65ddd569aaefa (patch)
tree289bf3468cc05ff203e5bad9abd14fa26113a9a1 /src/test
parentdac22ee43c841768900afbe5b7e697f0c515d2e0 (diff)
# Disallow TRUNCATE on tables that are involved in referential
constraints The issue with finding and removing foreign key constraints is no longer an issue, so please apply the attached. It does NOT check for rules or on delete triggers (old style foreign keys) as those are difficult to deal with (remove, truncate, re-add). Rod Taylor
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/truncate.out38
-rw-r--r--src/test/regress/parallel_schedule2
-rw-r--r--src/test/regress/serial_schedule3
-rw-r--r--src/test/regress/sql/truncate.sql17
4 files changed, 58 insertions, 2 deletions
diff --git a/src/test/regress/expected/truncate.out b/src/test/regress/expected/truncate.out
new file mode 100644
index 00000000000..19300f63a36
--- /dev/null
+++ b/src/test/regress/expected/truncate.out
@@ -0,0 +1,38 @@
+-- Test basic TRUNCATE functionality.
+CREATE TABLE truncate_a (col1 integer primary key);
+NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'truncate_a_pkey' for table 'truncate_a'
+INSERT INTO truncate_a VALUES (1);
+INSERT INTO truncate_a VALUES (2);
+SELECT * FROM truncate_a;
+ col1
+------
+ 1
+ 2
+(2 rows)
+
+TRUNCATE truncate_a;
+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;
+ERROR: TRUNCATE cannot be used as other tables reference this one via foreign key constraint $1
+SELECT * FROM truncate_a;
+ col1
+------
+ 1
+(1 row)
+
+DROP TABLE truncate_b;
+DROP TABLE truncate_a;
diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule
index 0ac26307063..e82d9421679 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -74,4 +74,4 @@ test: select_views alter_table portals_p2 rules foreign_key cluster
# The sixth group of parallel test
# ----------
# "plpgsql" cannot run concurrently with "rules"
-test: limit plpgsql temp domain rangefuncs copy2 conversion without_oid
+test: limit plpgsql temp domain rangefuncs copy2 conversion without_oid truncate
diff --git a/src/test/regress/serial_schedule b/src/test/regress/serial_schedule
index d7a6deed2c9..553df2dfe7d 100644
--- a/src/test/regress/serial_schedule
+++ b/src/test/regress/serial_schedule
@@ -1,4 +1,4 @@
-# $Header: /cvsroot/pgsql/src/test/regress/serial_schedule,v 1.15 2002/08/11 02:06:32 tgl Exp $
+# $Header: /cvsroot/pgsql/src/test/regress/serial_schedule,v 1.16 2002/08/22 04:51:06 momjian Exp $
# This should probably be in an order similar to parallel_schedule.
test: boolean
test: char
@@ -88,3 +88,4 @@ test: domain
test: rangefuncs
test: without_oid
test: conversion
+test: truncate
diff --git a/src/test/regress/sql/truncate.sql b/src/test/regress/sql/truncate.sql
new file mode 100644
index 00000000000..5333113a9e7
--- /dev/null
+++ b/src/test/regress/sql/truncate.sql
@@ -0,0 +1,17 @@
+-- Test basic TRUNCATE functionality.
+CREATE TABLE truncate_a (col1 integer primary key);
+INSERT INTO truncate_a VALUES (1);
+INSERT INTO truncate_a VALUES (2);
+SELECT * FROM truncate_a;
+TRUNCATE truncate_a;
+SELECT * FROM truncate_a;
+
+-- Test foreign constraint check
+CREATE TABLE truncate_b(col1 integer references truncate_a);
+INSERT INTO truncate_a VALUES (1);
+SELECT * FROM truncate_a;
+TRUNCATE truncate_a;
+SELECT * FROM truncate_a;
+
+DROP TABLE truncate_b;
+DROP TABLE truncate_a;