From 5a68fd56cd1d4a0c6fb0930f5145ed39b92f759b Mon Sep 17 00:00:00 2001
From: "Thomas G. Lockhart" <lockhart@fourpalms.org>
Date: Wed, 16 Sep 1998 14:35:37 +0000
Subject: [PATCH] Consolidate Jan's rules test into one file. Remove dependency
 on a specific Postgres user name in the results  (Check result against
 CURRENT_USER with a boolean instead).

---
 .../expected/{run_ruletest.out => rules.out}  | 188 +++++++++++++-----
 src/test/regress/expected/setup_ruletest.out  |  88 --------
 .../sql/{run_ruletest.sql => rules.sql}       | 153 +++++++++++++-
 src/test/regress/sql/setup_ruletest.sql       | 139 -------------
 src/test/regress/sql/tests                    |   3 +-
 5 files changed, 288 insertions(+), 283 deletions(-)
 rename src/test/regress/expected/{run_ruletest.out => rules.out} (63%)
 delete mode 100644 src/test/regress/expected/setup_ruletest.out
 rename src/test/regress/sql/{run_ruletest.sql => rules.sql} (61%)
 delete mode 100644 src/test/regress/sql/setup_ruletest.sql

diff --git a/src/test/regress/expected/run_ruletest.out b/src/test/regress/expected/rules.out
similarity index 63%
rename from src/test/regress/expected/run_ruletest.out
rename to src/test/regress/expected/rules.out
index 0421ad47b5d..447b1499faf 100644
--- a/src/test/regress/expected/run_ruletest.out
+++ b/src/test/regress/expected/rules.out
@@ -1,3 +1,91 @@
+QUERY: create table rtest_t1 (a int4, b int4);
+QUERY: create table rtest_t2 (a int4, b int4);
+QUERY: create table rtest_t3 (a int4, b int4);
+QUERY: create view rtest_v1 as select * from rtest_t1;
+QUERY: create rule rtest_v1_ins as on insert to rtest_v1 do instead
+	insert into rtest_t1 values (new.a, new.b);
+QUERY: create rule rtest_v1_upd as on update to rtest_v1 do instead
+	update rtest_t1 set a = new.a, b = new.b
+	where a = current.a;
+QUERY: create rule rtest_v1_del as on delete to rtest_v1 do instead
+	delete from rtest_t1 where a = current.a;
+QUERY: create table rtest_system (sysname text, sysdesc text);
+QUERY: create table rtest_interface (sysname text, ifname text);
+QUERY: create table rtest_person (pname text, pdesc text);
+QUERY: create table rtest_admin (pname text, sysname text);
+QUERY: create rule rtest_sys_upd1 as on update to rtest_system do
+	update rtest_interface set sysname = new.sysname
+		where sysname = current.sysname;
+QUERY: create rule rtest_sys_upd2 as on update to rtest_system do
+	update rtest_admin set sysname = new.sysname
+		where sysname = current.sysname;
+QUERY: create rule rtest_sys_del1 as on delete to rtest_system do
+	delete from rtest_interface where sysname = current.sysname;
+QUERY: create rule rtest_sys_del2 as on delete to rtest_system do
+	delete from rtest_admin where sysname = current.sysname;
+QUERY: create rule rtest_pers_upd as on update to rtest_person do
+	update rtest_admin set pname = new.pname where pname = current.pname;
+QUERY: create rule rtest_pers_del as on delete to rtest_person do
+	delete from rtest_admin where pname = current.pname;
+QUERY: create table rtest_emp (ename char(20), salary money);
+QUERY: create table rtest_emplog (ename char(20), who name, action char(10), newsal money, oldsal money);
+QUERY: create table rtest_empmass (ename char(20), salary money);
+QUERY: create rule rtest_emp_ins as on insert to rtest_emp do
+	insert into rtest_emplog values (new.ename, current_user,
+			'hired', new.salary, '0.00');
+QUERY: create rule rtest_emp_upd as on update to rtest_emp where new.salary != current.salary do
+	insert into rtest_emplog values (new.ename, current_user,
+			'honored', new.salary, current.salary);
+QUERY: create rule rtest_emp_del as on delete to rtest_emp do
+	insert into rtest_emplog values (current.ename, current_user,
+			'fired', '0.00', current.salary);
+QUERY: create table rtest_t4 (a int4, b text);
+QUERY: create table rtest_t5 (a int4, b text);
+QUERY: create table rtest_t6 (a int4, b text);
+QUERY: create table rtest_t7 (a int4, b text);
+QUERY: create table rtest_t8 (a int4, b text);
+QUERY: create table rtest_t9 (a int4, b text);
+QUERY: create rule rtest_t4_ins1 as on insert to rtest_t4
+		where new.a >= 10 and new.a < 20 do instead
+	insert into rtest_t5 values (new.a, new.b);
+QUERY: create rule rtest_t4_ins2 as on insert to rtest_t4
+		where new.a >= 20 and new.a < 30 do
+	insert into rtest_t6 values (new.a, new.b);
+QUERY: create rule rtest_t5_ins as on insert to rtest_t5
+		where new.a > 15 do
+	insert into rtest_t7 values (new.a, new.b);
+QUERY: create rule rtest_t6_ins as on insert to rtest_t6
+		where new.a > 25 do instead
+	insert into rtest_t8 values (new.a, new.b);
+QUERY: create table rtest_order1 (a int4);
+QUERY: create table rtest_order2 (a int4, b int4, c text);
+QUERY: create sequence rtest_seq;
+QUERY: create rule rtest_order_r3 as on insert to rtest_order1 do instead
+	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
+		'rule 3 - this should run 3rd or 4th');
+QUERY: create rule rtest_order_r4 as on insert to rtest_order1
+		where a < 100 do instead
+	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
+		'rule 4 - this should run 2nd');
+QUERY: create rule rtest_order_r2 as on insert to rtest_order1 do
+	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
+		'rule 2 - this should run 1st');
+QUERY: create rule rtest_order_r1 as on insert to rtest_order1 do instead
+	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
+		'rule 1 - this should run 3rd or 4th');
+QUERY: create table rtest_nothn1 (a int4, b text);
+QUERY: create table rtest_nothn2 (a int4, b text);
+QUERY: create table rtest_nothn3 (a int4, b text);
+QUERY: create table rtest_nothn4 (a int4, b text);
+QUERY: create rule rtest_nothn_r1 as on insert to rtest_nothn1
+	where new.a >= 10 and new.a < 20 do instead (select 1);
+QUERY: create rule rtest_nothn_r2 as on insert to rtest_nothn1
+	where new.a >= 30 and new.a < 40 do instead nothing;
+QUERY: create rule rtest_nothn_r3 as on insert to rtest_nothn2
+	where new.a >= 100 do instead
+	insert into rtest_nothn3 values (new.a, new.b);
+QUERY: create rule rtest_nothn_r4 as on insert to rtest_nothn2
+	do instead nothing;
 QUERY: insert into rtest_t2 values (1, 21);
 QUERY: insert into rtest_t2 values (2, 22);
 QUERY: insert into rtest_t2 values (3, 23);
@@ -252,69 +340,69 @@ QUERY: update rtest_emp set ename = 'wiecx' where ename = 'wiech';
 QUERY: update rtest_emp set ename = 'wieck', salary = '6000.00' where ename = 'wiecx';
 QUERY: update rtest_emp set salary = '7000.00' where ename = 'wieck';
 QUERY: delete from rtest_emp where ename = 'gates';
-QUERY: select * from rtest_emplog;
-ename               |who  |action    |newsal    |oldsal    
---------------------+-----+----------+----------+----------
-wiech               |pgsql|hired     |$5,000.00 |$0.00     
-gates               |pgsql|hired     |$80,000.00|$0.00     
-wieck               |pgsql|honored   |$6,000.00 |$5,000.00 
-wieck               |pgsql|honored   |$7,000.00 |$6,000.00 
-gates               |pgsql|fired     |$0.00     |$80,000.00
+QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog;
+ename               |matches user|action    |newsal    |oldsal    
+--------------------+------------+----------+----------+----------
+wiech               |t           |hired     |$5,000.00 |$0.00     
+gates               |t           |hired     |$80,000.00|$0.00     
+wieck               |t           |honored   |$6,000.00 |$5,000.00 
+wieck               |t           |honored   |$7,000.00 |$6,000.00 
+gates               |t           |fired     |$0.00     |$80,000.00
 (5 rows)
 
 QUERY: insert into rtest_empmass values ('meyer', '4000.00');
 QUERY: insert into rtest_empmass values ('maier', '5000.00');
 QUERY: insert into rtest_empmass values ('mayr', '6000.00');
 QUERY: insert into rtest_emp select * from rtest_empmass;
-QUERY: select * from rtest_emplog;
-ename               |who  |action    |newsal    |oldsal    
---------------------+-----+----------+----------+----------
-wiech               |pgsql|hired     |$5,000.00 |$0.00     
-gates               |pgsql|hired     |$80,000.00|$0.00     
-wieck               |pgsql|honored   |$6,000.00 |$5,000.00 
-wieck               |pgsql|honored   |$7,000.00 |$6,000.00 
-gates               |pgsql|fired     |$0.00     |$80,000.00
-meyer               |pgsql|hired     |$4,000.00 |$0.00     
-maier               |pgsql|hired     |$5,000.00 |$0.00     
-mayr                |pgsql|hired     |$6,000.00 |$0.00     
+QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog;
+ename               |matches user|action    |newsal    |oldsal    
+--------------------+------------+----------+----------+----------
+wiech               |t           |hired     |$5,000.00 |$0.00     
+gates               |t           |hired     |$80,000.00|$0.00     
+wieck               |t           |honored   |$6,000.00 |$5,000.00 
+wieck               |t           |honored   |$7,000.00 |$6,000.00 
+gates               |t           |fired     |$0.00     |$80,000.00
+meyer               |t           |hired     |$4,000.00 |$0.00     
+maier               |t           |hired     |$5,000.00 |$0.00     
+mayr                |t           |hired     |$6,000.00 |$0.00     
 (8 rows)
 
 QUERY: update rtest_empmass set salary = salary + '1000.00';
 QUERY: update rtest_emp set salary = rtest_empmass.salary where ename = rtest_empmass.ename;
-QUERY: select * from rtest_emplog;
-ename               |who  |action    |newsal    |oldsal    
---------------------+-----+----------+----------+----------
-wiech               |pgsql|hired     |$5,000.00 |$0.00     
-gates               |pgsql|hired     |$80,000.00|$0.00     
-wieck               |pgsql|honored   |$6,000.00 |$5,000.00 
-wieck               |pgsql|honored   |$7,000.00 |$6,000.00 
-gates               |pgsql|fired     |$0.00     |$80,000.00
-meyer               |pgsql|hired     |$4,000.00 |$0.00     
-maier               |pgsql|hired     |$5,000.00 |$0.00     
-mayr                |pgsql|hired     |$6,000.00 |$0.00     
-maier               |pgsql|honored   |$6,000.00 |$5,000.00 
-mayr                |pgsql|honored   |$7,000.00 |$6,000.00 
-meyer               |pgsql|honored   |$5,000.00 |$4,000.00 
+QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog;
+ename               |matches user|action    |newsal    |oldsal    
+--------------------+------------+----------+----------+----------
+wiech               |t           |hired     |$5,000.00 |$0.00     
+gates               |t           |hired     |$80,000.00|$0.00     
+wieck               |t           |honored   |$6,000.00 |$5,000.00 
+wieck               |t           |honored   |$7,000.00 |$6,000.00 
+gates               |t           |fired     |$0.00     |$80,000.00
+meyer               |t           |hired     |$4,000.00 |$0.00     
+maier               |t           |hired     |$5,000.00 |$0.00     
+mayr                |t           |hired     |$6,000.00 |$0.00     
+maier               |t           |honored   |$6,000.00 |$5,000.00 
+mayr                |t           |honored   |$7,000.00 |$6,000.00 
+meyer               |t           |honored   |$5,000.00 |$4,000.00 
 (11 rows)
 
 QUERY: delete from rtest_emp where ename = rtest_empmass.ename;
-QUERY: select * from rtest_emplog;
-ename               |who  |action    |newsal    |oldsal    
---------------------+-----+----------+----------+----------
-wiech               |pgsql|hired     |$5,000.00 |$0.00     
-gates               |pgsql|hired     |$80,000.00|$0.00     
-wieck               |pgsql|honored   |$6,000.00 |$5,000.00 
-wieck               |pgsql|honored   |$7,000.00 |$6,000.00 
-gates               |pgsql|fired     |$0.00     |$80,000.00
-meyer               |pgsql|hired     |$4,000.00 |$0.00     
-maier               |pgsql|hired     |$5,000.00 |$0.00     
-mayr                |pgsql|hired     |$6,000.00 |$0.00     
-maier               |pgsql|honored   |$6,000.00 |$5,000.00 
-mayr                |pgsql|honored   |$7,000.00 |$6,000.00 
-meyer               |pgsql|honored   |$5,000.00 |$4,000.00 
-maier               |pgsql|fired     |$0.00     |$6,000.00 
-mayr                |pgsql|fired     |$0.00     |$7,000.00 
-meyer               |pgsql|fired     |$0.00     |$5,000.00 
+QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog;
+ename               |matches user|action    |newsal    |oldsal    
+--------------------+------------+----------+----------+----------
+wiech               |t           |hired     |$5,000.00 |$0.00     
+gates               |t           |hired     |$80,000.00|$0.00     
+wieck               |t           |honored   |$6,000.00 |$5,000.00 
+wieck               |t           |honored   |$7,000.00 |$6,000.00 
+gates               |t           |fired     |$0.00     |$80,000.00
+meyer               |t           |hired     |$4,000.00 |$0.00     
+maier               |t           |hired     |$5,000.00 |$0.00     
+mayr                |t           |hired     |$6,000.00 |$0.00     
+maier               |t           |honored   |$6,000.00 |$5,000.00 
+mayr                |t           |honored   |$7,000.00 |$6,000.00 
+meyer               |t           |honored   |$5,000.00 |$4,000.00 
+maier               |t           |fired     |$0.00     |$6,000.00 
+mayr                |t           |fired     |$0.00     |$7,000.00 
+meyer               |t           |fired     |$0.00     |$5,000.00 
 (14 rows)
 
 QUERY: insert into rtest_t4 values (1, 'Record should go to rtest_t4');
diff --git a/src/test/regress/expected/setup_ruletest.out b/src/test/regress/expected/setup_ruletest.out
deleted file mode 100644
index 9cd3c09026a..00000000000
--- a/src/test/regress/expected/setup_ruletest.out
+++ /dev/null
@@ -1,88 +0,0 @@
-QUERY: create table rtest_t1 (a int4, b int4);
-QUERY: create table rtest_t2 (a int4, b int4);
-QUERY: create table rtest_t3 (a int4, b int4);
-QUERY: create view rtest_v1 as select * from rtest_t1;
-QUERY: create rule rtest_v1_ins as on insert to rtest_v1 do instead
-	insert into rtest_t1 values (new.a, new.b);
-QUERY: create rule rtest_v1_upd as on update to rtest_v1 do instead
-	update rtest_t1 set a = new.a, b = new.b
-	where a = current.a;
-QUERY: create rule rtest_v1_del as on delete to rtest_v1 do instead
-	delete from rtest_t1 where a = current.a;
-QUERY: create table rtest_system (sysname text, sysdesc text);
-QUERY: create table rtest_interface (sysname text, ifname text);
-QUERY: create table rtest_person (pname text, pdesc text);
-QUERY: create table rtest_admin (pname text, sysname text);
-QUERY: create rule rtest_sys_upd1 as on update to rtest_system do
-	update rtest_interface set sysname = new.sysname
-		where sysname = current.sysname;
-QUERY: create rule rtest_sys_upd2 as on update to rtest_system do
-	update rtest_admin set sysname = new.sysname
-		where sysname = current.sysname;
-QUERY: create rule rtest_sys_del1 as on delete to rtest_system do
-	delete from rtest_interface where sysname = current.sysname;
-QUERY: create rule rtest_sys_del2 as on delete to rtest_system do
-	delete from rtest_admin where sysname = current.sysname;
-QUERY: create rule rtest_pers_upd as on update to rtest_person do
-	update rtest_admin set pname = new.pname where pname = current.pname;
-QUERY: create rule rtest_pers_del as on delete to rtest_person do
-	delete from rtest_admin where pname = current.pname;
-QUERY: create table rtest_emp (ename char(20), salary money);
-QUERY: create table rtest_emplog (ename char(20), who name, action char(10), newsal money, oldsal money);
-QUERY: create table rtest_empmass (ename char(20), salary money);
-QUERY: create rule rtest_emp_ins as on insert to rtest_emp do
-	insert into rtest_emplog values (new.ename, getpgusername(),
-			'hired', new.salary, '0.00');
-QUERY: create rule rtest_emp_upd as on update to rtest_emp where new.salary != current.salary do
-	insert into rtest_emplog values (new.ename, getpgusername(),
-			'honored', new.salary, current.salary);
-QUERY: create rule rtest_emp_del as on delete to rtest_emp do
-	insert into rtest_emplog values (current.ename, getpgusername(),
-			'fired', '0.00', current.salary);
-QUERY: create table rtest_t4 (a int4, b text);
-QUERY: create table rtest_t5 (a int4, b text);
-QUERY: create table rtest_t6 (a int4, b text);
-QUERY: create table rtest_t7 (a int4, b text);
-QUERY: create table rtest_t8 (a int4, b text);
-QUERY: create table rtest_t9 (a int4, b text);
-QUERY: create rule rtest_t4_ins1 as on insert to rtest_t4
-		where new.a >= 10 and new.a < 20 do instead
-	insert into rtest_t5 values (new.a, new.b);
-QUERY: create rule rtest_t4_ins2 as on insert to rtest_t4
-		where new.a >= 20 and new.a < 30 do
-	insert into rtest_t6 values (new.a, new.b);
-QUERY: create rule rtest_t5_ins as on insert to rtest_t5
-		where new.a > 15 do
-	insert into rtest_t7 values (new.a, new.b);
-QUERY: create rule rtest_t6_ins as on insert to rtest_t6
-		where new.a > 25 do instead
-	insert into rtest_t8 values (new.a, new.b);
-QUERY: create table rtest_order1 (a int4);
-QUERY: create table rtest_order2 (a int4, b int4, c text);
-QUERY: create sequence rtest_seq;
-QUERY: create rule rtest_order_r3 as on insert to rtest_order1 do instead
-	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
-		'rule 3 - this should run 3rd or 4th');
-QUERY: create rule rtest_order_r4 as on insert to rtest_order1
-		where a < 100 do instead
-	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
-		'rule 4 - this should run 2nd');
-QUERY: create rule rtest_order_r2 as on insert to rtest_order1 do
-	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
-		'rule 2 - this should run 1st');
-QUERY: create rule rtest_order_r1 as on insert to rtest_order1 do instead
-	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
-		'rule 1 - this should run 3rd or 4th');
-QUERY: create table rtest_nothn1 (a int4, b text);
-QUERY: create table rtest_nothn2 (a int4, b text);
-QUERY: create table rtest_nothn3 (a int4, b text);
-QUERY: create table rtest_nothn4 (a int4, b text);
-QUERY: create rule rtest_nothn_r1 as on insert to rtest_nothn1
-	where new.a >= 10 and new.a < 20 do instead (select 1);
-QUERY: create rule rtest_nothn_r2 as on insert to rtest_nothn1
-	where new.a >= 30 and new.a < 40 do instead nothing;
-QUERY: create rule rtest_nothn_r3 as on insert to rtest_nothn2
-	where new.a >= 100 do instead
-	insert into rtest_nothn3 values (new.a, new.b);
-QUERY: create rule rtest_nothn_r4 as on insert to rtest_nothn2
-	do instead nothing;
diff --git a/src/test/regress/sql/run_ruletest.sql b/src/test/regress/sql/rules.sql
similarity index 61%
rename from src/test/regress/sql/run_ruletest.sql
rename to src/test/regress/sql/rules.sql
index ea18e68aa57..6ca18775863 100644
--- a/src/test/regress/sql/run_ruletest.sql
+++ b/src/test/regress/sql/rules.sql
@@ -1,3 +1,148 @@
+--
+-- rules.sql
+-- From Jan's original setup_ruletest.sql and run_ruletest.sql
+-- - thomas 1998-09-13
+--
+
+--
+-- Tables and rules for the view test
+--
+create table rtest_t1 (a int4, b int4);
+create table rtest_t2 (a int4, b int4);
+create table rtest_t3 (a int4, b int4);
+
+create view rtest_v1 as select * from rtest_t1;
+create rule rtest_v1_ins as on insert to rtest_v1 do instead
+	insert into rtest_t1 values (new.a, new.b);
+create rule rtest_v1_upd as on update to rtest_v1 do instead
+	update rtest_t1 set a = new.a, b = new.b
+	where a = current.a;
+create rule rtest_v1_del as on delete to rtest_v1 do instead
+	delete from rtest_t1 where a = current.a;
+
+--
+-- Tables and rules for the constraint update/delete test
+--
+-- Note:
+-- 	psql prevents from putting colons into brackets as
+-- 	required for multi action rules. So we define single
+-- 	rules for each action required for now
+--
+create table rtest_system (sysname text, sysdesc text);
+create table rtest_interface (sysname text, ifname text);
+create table rtest_person (pname text, pdesc text);
+create table rtest_admin (pname text, sysname text);
+
+create rule rtest_sys_upd1 as on update to rtest_system do 
+	update rtest_interface set sysname = new.sysname 
+		where sysname = current.sysname;
+create rule rtest_sys_upd2 as on update to rtest_system do 
+	update rtest_admin set sysname = new.sysname 
+		where sysname = current.sysname;
+
+create rule rtest_sys_del1 as on delete to rtest_system do
+	delete from rtest_interface where sysname = current.sysname;
+create rule rtest_sys_del2 as on delete to rtest_system do
+	delete from rtest_admin where sysname = current.sysname;
+
+create rule rtest_pers_upd as on update to rtest_person do 
+	update rtest_admin set pname = new.pname where pname = current.pname;
+
+create rule rtest_pers_del as on delete to rtest_person do 
+	delete from rtest_admin where pname = current.pname;
+
+--
+-- Tables and rules for the logging test
+--
+create table rtest_emp (ename char(20), salary money);
+create table rtest_emplog (ename char(20), who name, action char(10), newsal money, oldsal money);
+create table rtest_empmass (ename char(20), salary money);
+
+create rule rtest_emp_ins as on insert to rtest_emp do
+	insert into rtest_emplog values (new.ename, current_user,
+			'hired', new.salary, '0.00');
+
+create rule rtest_emp_upd as on update to rtest_emp where new.salary != current.salary do
+	insert into rtest_emplog values (new.ename, current_user,
+			'honored', new.salary, current.salary);
+
+create rule rtest_emp_del as on delete to rtest_emp do
+	insert into rtest_emplog values (current.ename, current_user,
+			'fired', '0.00', current.salary);
+
+--
+-- Tables and rules for the multiple cascaded qualified instead
+-- rule test 
+--
+create table rtest_t4 (a int4, b text);
+create table rtest_t5 (a int4, b text);
+create table rtest_t6 (a int4, b text);
+create table rtest_t7 (a int4, b text);
+create table rtest_t8 (a int4, b text);
+create table rtest_t9 (a int4, b text);
+
+create rule rtest_t4_ins1 as on insert to rtest_t4
+		where new.a >= 10 and new.a < 20 do instead
+	insert into rtest_t5 values (new.a, new.b);
+
+create rule rtest_t4_ins2 as on insert to rtest_t4
+		where new.a >= 20 and new.a < 30 do
+	insert into rtest_t6 values (new.a, new.b);
+
+create rule rtest_t5_ins as on insert to rtest_t5
+		where new.a > 15 do
+	insert into rtest_t7 values (new.a, new.b);
+
+create rule rtest_t6_ins as on insert to rtest_t6
+		where new.a > 25 do instead
+	insert into rtest_t8 values (new.a, new.b);
+
+--
+-- Tables and rules for the rule fire order test
+--
+create table rtest_order1 (a int4);
+create table rtest_order2 (a int4, b int4, c text);
+
+create sequence rtest_seq;
+
+create rule rtest_order_r3 as on insert to rtest_order1 do instead
+	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
+		'rule 3 - this should run 3rd or 4th');
+
+create rule rtest_order_r4 as on insert to rtest_order1
+		where a < 100 do instead
+	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
+		'rule 4 - this should run 2nd');
+
+create rule rtest_order_r2 as on insert to rtest_order1 do
+	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
+		'rule 2 - this should run 1st');
+
+create rule rtest_order_r1 as on insert to rtest_order1 do instead
+	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
+		'rule 1 - this should run 3rd or 4th');
+
+--
+-- Tables and rules for the instead nothing test
+--
+create table rtest_nothn1 (a int4, b text);
+create table rtest_nothn2 (a int4, b text);
+create table rtest_nothn3 (a int4, b text);
+create table rtest_nothn4 (a int4, b text);
+
+create rule rtest_nothn_r1 as on insert to rtest_nothn1
+	where new.a >= 10 and new.a < 20 do instead (select 1);
+
+create rule rtest_nothn_r2 as on insert to rtest_nothn1
+	where new.a >= 30 and new.a < 40 do instead nothing;
+
+create rule rtest_nothn_r3 as on insert to rtest_nothn2
+	where new.a >= 100 do instead
+	insert into rtest_nothn3 values (new.a, new.b);
+
+create rule rtest_nothn_r4 as on insert to rtest_nothn2
+	do instead nothing;
+
 --
 -- Tests on a view that is select * of a table
 -- and has insert/update/delete instead rules to
@@ -123,17 +268,17 @@ update rtest_emp set ename = 'wieck', salary = '6000.00' where ename = 'wiecx';
 update rtest_emp set salary = '7000.00' where ename = 'wieck';
 delete from rtest_emp where ename = 'gates';
 
-select * from rtest_emplog;
+select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog;
 insert into rtest_empmass values ('meyer', '4000.00');
 insert into rtest_empmass values ('maier', '5000.00');
 insert into rtest_empmass values ('mayr', '6000.00');
 insert into rtest_emp select * from rtest_empmass;
-select * from rtest_emplog;
+select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog;
 update rtest_empmass set salary = salary + '1000.00';
 update rtest_emp set salary = rtest_empmass.salary where ename = rtest_empmass.ename;
-select * from rtest_emplog;
+select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog;
 delete from rtest_emp where ename = rtest_empmass.ename;
-select * from rtest_emplog;
+select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog;
 
 --
 -- Multiple cascaded qualified instead rule test
diff --git a/src/test/regress/sql/setup_ruletest.sql b/src/test/regress/sql/setup_ruletest.sql
deleted file mode 100644
index ea9db0b7437..00000000000
--- a/src/test/regress/sql/setup_ruletest.sql
+++ /dev/null
@@ -1,139 +0,0 @@
---
--- Tables and rules for the view test
---
-create table rtest_t1 (a int4, b int4);
-create table rtest_t2 (a int4, b int4);
-create table rtest_t3 (a int4, b int4);
-
-create view rtest_v1 as select * from rtest_t1;
-create rule rtest_v1_ins as on insert to rtest_v1 do instead
-	insert into rtest_t1 values (new.a, new.b);
-create rule rtest_v1_upd as on update to rtest_v1 do instead
-	update rtest_t1 set a = new.a, b = new.b
-	where a = current.a;
-create rule rtest_v1_del as on delete to rtest_v1 do instead
-	delete from rtest_t1 where a = current.a;
-
---
--- Tables and rules for the constraint update/delete test
---
--- Note:
--- 	psql prevents from putting colons into brackets as
--- 	required for multi action rules. So we define single
--- 	rules for each action required for now
---
-create table rtest_system (sysname text, sysdesc text);
-create table rtest_interface (sysname text, ifname text);
-create table rtest_person (pname text, pdesc text);
-create table rtest_admin (pname text, sysname text);
-
-create rule rtest_sys_upd1 as on update to rtest_system do 
-	update rtest_interface set sysname = new.sysname 
-		where sysname = current.sysname;
-create rule rtest_sys_upd2 as on update to rtest_system do 
-	update rtest_admin set sysname = new.sysname 
-		where sysname = current.sysname;
-
-create rule rtest_sys_del1 as on delete to rtest_system do
-	delete from rtest_interface where sysname = current.sysname;
-create rule rtest_sys_del2 as on delete to rtest_system do
-	delete from rtest_admin where sysname = current.sysname;
-
-create rule rtest_pers_upd as on update to rtest_person do 
-	update rtest_admin set pname = new.pname where pname = current.pname;
-
-create rule rtest_pers_del as on delete to rtest_person do 
-	delete from rtest_admin where pname = current.pname;
-
---
--- Tables and rules for the logging test
---
-create table rtest_emp (ename char(20), salary money);
-create table rtest_emplog (ename char(20), who name, action char(10), newsal money, oldsal money);
-create table rtest_empmass (ename char(20), salary money);
-
-create rule rtest_emp_ins as on insert to rtest_emp do
-	insert into rtest_emplog values (new.ename, getpgusername(),
-			'hired', new.salary, '0.00');
-
-create rule rtest_emp_upd as on update to rtest_emp where new.salary != current.salary do
-	insert into rtest_emplog values (new.ename, getpgusername(),
-			'honored', new.salary, current.salary);
-
-create rule rtest_emp_del as on delete to rtest_emp do
-	insert into rtest_emplog values (current.ename, getpgusername(),
-			'fired', '0.00', current.salary);
-
---
--- Tables and rules for the multiple cascaded qualified instead
--- rule test 
---
-create table rtest_t4 (a int4, b text);
-create table rtest_t5 (a int4, b text);
-create table rtest_t6 (a int4, b text);
-create table rtest_t7 (a int4, b text);
-create table rtest_t8 (a int4, b text);
-create table rtest_t9 (a int4, b text);
-
-create rule rtest_t4_ins1 as on insert to rtest_t4
-		where new.a >= 10 and new.a < 20 do instead
-	insert into rtest_t5 values (new.a, new.b);
-
-create rule rtest_t4_ins2 as on insert to rtest_t4
-		where new.a >= 20 and new.a < 30 do
-	insert into rtest_t6 values (new.a, new.b);
-
-create rule rtest_t5_ins as on insert to rtest_t5
-		where new.a > 15 do
-	insert into rtest_t7 values (new.a, new.b);
-
-create rule rtest_t6_ins as on insert to rtest_t6
-		where new.a > 25 do instead
-	insert into rtest_t8 values (new.a, new.b);
-
---
--- Tables and rules for the rule fire order test
---
-create table rtest_order1 (a int4);
-create table rtest_order2 (a int4, b int4, c text);
-
-create sequence rtest_seq;
-
-create rule rtest_order_r3 as on insert to rtest_order1 do instead
-	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
-		'rule 3 - this should run 3rd or 4th');
-
-create rule rtest_order_r4 as on insert to rtest_order1
-		where a < 100 do instead
-	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
-		'rule 4 - this should run 2nd');
-
-create rule rtest_order_r2 as on insert to rtest_order1 do
-	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
-		'rule 2 - this should run 1st');
-
-create rule rtest_order_r1 as on insert to rtest_order1 do instead
-	insert into rtest_order2 values (new.a, nextval('rtest_seq'),
-		'rule 1 - this should run 3rd or 4th');
-
---
--- Tables and rules for the instead nothing test
---
-create table rtest_nothn1 (a int4, b text);
-create table rtest_nothn2 (a int4, b text);
-create table rtest_nothn3 (a int4, b text);
-create table rtest_nothn4 (a int4, b text);
-
-create rule rtest_nothn_r1 as on insert to rtest_nothn1
-	where new.a >= 10 and new.a < 20 do instead (select 1);
-
-create rule rtest_nothn_r2 as on insert to rtest_nothn1
-	where new.a >= 30 and new.a < 40 do instead nothing;
-
-create rule rtest_nothn_r3 as on insert to rtest_nothn2
-	where new.a >= 100 do instead
-	insert into rtest_nothn3 values (new.a, new.b);
-
-create rule rtest_nothn_r4 as on insert to rtest_nothn2
-	do instead nothing;
-
diff --git a/src/test/regress/sql/tests b/src/test/regress/sql/tests
index e8446796ad5..d4ba89aa345 100644
--- a/src/test/regress/sql/tests
+++ b/src/test/regress/sql/tests
@@ -58,5 +58,4 @@ hash_index
 select_views
 alter_table
 portals_p2
-setup_ruletest
-run_ruletest
+rules
-- 
GitLab