📄 rules.out
字号:
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 = old.a;QUERY: create rule rtest_v1_del as on delete to rtest_v1 do instead delete from rtest_t1 where a = old.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_upd as on update to rtest_system do ( update rtest_interface set sysname = new.sysname where sysname = old.sysname; update rtest_admin set sysname = new.sysname where sysname = old.sysname );QUERY: create rule rtest_sys_del as on delete to rtest_system do ( delete from rtest_interface where sysname = old.sysname; delete from rtest_admin where sysname = old.sysname; );QUERY: create rule rtest_pers_upd as on update to rtest_person do update rtest_admin set pname = new.pname where pname = old.pname;QUERY: create rule rtest_pers_del as on delete to rtest_person do delete from rtest_admin where pname = old.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 != old.salary do insert into rtest_emplog values (new.ename, current_user, 'honored', new.salary, old.salary);QUERY: create rule rtest_emp_del as on delete to rtest_emp do insert into rtest_emplog values (old.ename, current_user, 'fired', '0.00', old.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);QUERY: insert into rtest_t3 values (1, 31);QUERY: insert into rtest_t3 values (2, 32);QUERY: insert into rtest_t3 values (3, 33);QUERY: insert into rtest_t3 values (4, 34);QUERY: insert into rtest_t3 values (5, 35);QUERY: insert into rtest_v1 values (1, 11);QUERY: insert into rtest_v1 values (2, 12);QUERY: select * from rtest_v1;a| b-+--1|112|12(2 rows)QUERY: delete from rtest_v1 where a = 1;QUERY: select * from rtest_v1;a| b-+--2|12(1 row)QUERY: insert into rtest_v1 values (1, 11);QUERY: delete from rtest_v1 where b = 12;QUERY: select * from rtest_v1;a| b-+--1|11(1 row)QUERY: insert into rtest_v1 values (2, 12);QUERY: insert into rtest_v1 values (2, 13);QUERY: select * from rtest_v1;a| b-+--1|112|122|13(3 rows)QUERY: delete from rtest_v1 where b = 12;QUERY: select * from rtest_v1;** Remember the delete rule on rtest_v1: It says** DO INSTEAD DELETE FROM rtest_t1 WHERE a = old.a** So this time both rows with a = 2 must get deleteda| b-+--1|11(1 row)QUERY: delete from rtest_v1;QUERY: insert into rtest_v1 select * from rtest_t2;QUERY: select * from rtest_v1;a| b-+--1|212|223|23(3 rows)QUERY: delete from rtest_v1;QUERY: insert into rtest_v1 (b, a) select b, a from rtest_t2;QUERY: select * from rtest_v1;a| b-+--1|212|223|23(3 rows)QUERY: insert into rtest_v1 (a) select a from rtest_t3;QUERY: select * from rtest_v1;a| b-+--1|212|223|231| 2| 3| 4| 5| (8 rows)QUERY: select * from rtest_v1 where b isnull;a|b-+-1| 2| 3| 4| 5| (5 rows)QUERY: update rtest_t1 set a = a + 10 where b isnull;QUERY: delete from rtest_v1 where b isnull;QUERY: select * from rtest_v1;a| b-+--1|212|223|23(3 rows)QUERY: update rtest_v1 set b = 42 where a = 2;QUERY: select * from rtest_v1;a| b-+--1|213|232|42(3 rows)QUERY: update rtest_v1 set b = 99 where b = 42;QUERY: select * from rtest_v1;a| b-+--1|213|232|99(3 rows)QUERY: update rtest_v1 set b = 88 where b < 50;QUERY: select * from rtest_v1;a| b-+--2|991|883|88(3 rows)QUERY: delete from rtest_v1;QUERY: insert into rtest_v1 select rtest_t2.a, rtest_t3.b where rtest_t2.a = rtest_t3.a;QUERY: select * from rtest_v1;a| b-+--1|312|323|33(3 rows)QUERY: update rtest_v1 set b = rtest_t2.b where a = rtest_t2.a;QUERY: select * from rtest_v1;a| b-+--1|212|223|23(3 rows)QUERY: insert into rtest_v1 select * from rtest_t3;QUERY: select * from rtest_v1;a| b-+--1|212|223|231|312|323|334|345|35(8 rows)QUERY: update rtest_t1 set a = a + 10 where b > 30;QUERY: select * from rtest_v1; a| b--+-- 1|21 2|22 3|2311|3112|3213|3314|3415|35(8 rows)QUERY: update rtest_v1 set a = rtest_t3.a + 20 where b = rtest_t3.b;QUERY: select * from rtest_v1; a| b--+-- 1|21 2|22 3|2321|3122|3223|3324|3425|35(8 rows)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -