Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5ce8ab9

Browse files
committed
Add regress test case for INSERT ... SELECT in rules.
1 parent a51f004 commit 5ce8ab9

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

src/test/regress/expected/rules.out

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,67 @@ drop rule foorule;
12001200
drop table foo;
12011201
drop table foo2;
12021202
--
1203+
-- Test rules containing INSERT ... SELECT, which is a very ugly special
1204+
-- case as of 7.1. Example is based on bug report from Joel Burton.
1205+
--
1206+
create table pparent (pid int, txt text);
1207+
insert into pparent values (1,'parent1');
1208+
insert into pparent values (2,'parent2');
1209+
create table cchild (pid int, descrip text);
1210+
insert into cchild values (1,'descrip1');
1211+
create view vview as
1212+
select pparent.pid, txt, descrip from
1213+
pparent left join cchild using (pid);
1214+
create rule rrule as
1215+
on update to vview do instead
1216+
(
1217+
insert into cchild (pid, descrip)
1218+
select old.pid, new.descrip where old.descrip isnull;
1219+
update cchild set descrip = new.descrip where cchild.pid = old.pid;
1220+
);
1221+
select * from vview;
1222+
pid | txt | descrip
1223+
-----+---------+----------
1224+
1 | parent1 | descrip1
1225+
2 | parent2 |
1226+
(2 rows)
1227+
1228+
update vview set descrip='test1' where pid=1;
1229+
select * from vview;
1230+
pid | txt | descrip
1231+
-----+---------+---------
1232+
1 | parent1 | test1
1233+
2 | parent2 |
1234+
(2 rows)
1235+
1236+
update vview set descrip='test2' where pid=2;
1237+
select * from vview;
1238+
pid | txt | descrip
1239+
-----+---------+---------
1240+
1 | parent1 | test1
1241+
2 | parent2 | test2
1242+
(2 rows)
1243+
1244+
update vview set descrip='test3' where pid=3;
1245+
select * from vview;
1246+
pid | txt | descrip
1247+
-----+---------+---------
1248+
1 | parent1 | test1
1249+
2 | parent2 | test2
1250+
(2 rows)
1251+
1252+
select * from cchild;
1253+
pid | descrip
1254+
-----+---------
1255+
1 | test1
1256+
2 | test2
1257+
(2 rows)
1258+
1259+
drop rule rrule;
1260+
drop view vview;
1261+
drop table pparent;
1262+
drop table cchild;
1263+
--
12031264
-- Check that ruleutils are working
12041265
--
12051266
SELECT viewname, definition FROM pg_views ORDER BY viewname;

src/test/regress/sql/rules.sql

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,44 @@ drop table foo;
719719
drop table foo2;
720720

721721

722+
--
723+
-- Test rules containing INSERT ... SELECT, which is a very ugly special
724+
-- case as of 7.1. Example is based on bug report from Joel Burton.
725+
--
726+
create table pparent (pid int, txt text);
727+
insert into pparent values (1,'parent1');
728+
insert into pparent values (2,'parent2');
729+
730+
create table cchild (pid int, descrip text);
731+
insert into cchild values (1,'descrip1');
732+
733+
create view vview as
734+
select pparent.pid, txt, descrip from
735+
pparent left join cchild using (pid);
736+
737+
create rule rrule as
738+
on update to vview do instead
739+
(
740+
insert into cchild (pid, descrip)
741+
select old.pid, new.descrip where old.descrip isnull;
742+
update cchild set descrip = new.descrip where cchild.pid = old.pid;
743+
);
744+
745+
select * from vview;
746+
update vview set descrip='test1' where pid=1;
747+
select * from vview;
748+
update vview set descrip='test2' where pid=2;
749+
select * from vview;
750+
update vview set descrip='test3' where pid=3;
751+
select * from vview;
752+
select * from cchild;
753+
754+
drop rule rrule;
755+
drop view vview;
756+
drop table pparent;
757+
drop table cchild;
758+
759+
722760
--
723761
-- Check that ruleutils are working
724762
--

0 commit comments

Comments
 (0)