postgresql/src/test/regress/expected/rules.out

1067 lines
34 KiB
Plaintext
Raw Normal View History

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|11
2|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|11
2|12
2|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 deleted
a| 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|21
2|22
3|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|21
2|22
3|23
(3 rows)
QUERY: insert into rtest_v1 (a) select a from rtest_t3;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
2|22
3|23
1|
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|21
2|22
3|23
(3 rows)
QUERY: update rtest_v1 set b = 42 where a = 2;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
3|23
2|42
(3 rows)
QUERY: update rtest_v1 set b = 99 where b = 42;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
3|23
2|99
(3 rows)
QUERY: update rtest_v1 set b = 88 where b < 50;
QUERY: select * from rtest_v1;
a| b
-+--
2|99
1|88
3|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|31
2|32
3|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|21
2|22
3|23
(3 rows)
QUERY: insert into rtest_v1 select * from rtest_t3;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
2|22
3|23
1|31
2|32
3|33
4|34
5|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|23
11|31
12|32
13|33
14|34
15|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|23
21|31
22|32
23|33
24|34
25|35
(8 rows)
QUERY: insert into rtest_system values ('orion', 'Linux Jan Wieck');
QUERY: insert into rtest_system values ('notjw', 'WinNT Jan Wieck (notebook)');
QUERY: insert into rtest_system values ('neptun', 'Fileserver');
QUERY: insert into rtest_interface values ('orion', 'eth0');
QUERY: insert into rtest_interface values ('orion', 'eth1');
QUERY: insert into rtest_interface values ('notjw', 'eth0');
QUERY: insert into rtest_interface values ('neptun', 'eth0');
QUERY: insert into rtest_person values ('jw', 'Jan Wieck');
QUERY: insert into rtest_person values ('bm', 'Bruce Momjian');
QUERY: insert into rtest_admin values ('jw', 'orion');
QUERY: insert into rtest_admin values ('jw', 'notjw');
QUERY: insert into rtest_admin values ('bm', 'neptun');
QUERY: update rtest_system set sysname = 'pluto' where sysname = 'neptun';
QUERY: select * from rtest_interface;
sysname|ifname
-------+------
orion |eth0
orion |eth1
notjw |eth0
pluto |eth0
(4 rows)
QUERY: select * from rtest_admin;
pname|sysname
-----+-------
jw |orion
jw |notjw
bm |pluto
(3 rows)
QUERY: update rtest_person set pname = 'jwieck' where pdesc = 'Jan Wieck';
QUERY: select * from rtest_admin order by pname, sysname;
pname |sysname
------+-------
bm |pluto
jwieck|notjw
jwieck|orion
(3 rows)
QUERY: delete from rtest_system where sysname = 'orion';
QUERY: select * from rtest_interface;
sysname|ifname
-------+------
notjw |eth0
pluto |eth0
(2 rows)
QUERY: select * from rtest_admin;
pname |sysname
------+-------
bm |pluto
jwieck|notjw
(2 rows)
QUERY: insert into rtest_emp values ('wiech', '5000.00');
QUERY: insert into rtest_emp values ('gates', '80000.00');
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 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 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 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 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');
QUERY: insert into rtest_t4 values (2, 'Record should go to rtest_t4');
QUERY: insert into rtest_t4 values (10, 'Record should go to rtest_t5');
QUERY: insert into rtest_t4 values (15, 'Record should go to rtest_t5');
QUERY: insert into rtest_t4 values (19, 'Record should go to rtest_t5 and t7');
QUERY: insert into rtest_t4 values (20, 'Record should go to rtest_t4 and t6');
QUERY: insert into rtest_t4 values (26, 'Record should go to rtest_t4 and t8');
QUERY: insert into rtest_t4 values (28, 'Record should go to rtest_t4 and t8');
QUERY: insert into rtest_t4 values (30, 'Record should go to rtest_t4');
QUERY: insert into rtest_t4 values (40, 'Record should go to rtest_t4');
QUERY: select * from rtest_t4;
a|b
--+-----------------------------------
1|Record should go to rtest_t4
2|Record should go to rtest_t4
20|Record should go to rtest_t4 and t6
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
30|Record should go to rtest_t4
40|Record should go to rtest_t4
(7 rows)
QUERY: select * from rtest_t5;
a|b
--+-----------------------------------
10|Record should go to rtest_t5
15|Record should go to rtest_t5
19|Record should go to rtest_t5 and t7
(3 rows)
QUERY: select * from rtest_t6;
a|b
--+-----------------------------------
20|Record should go to rtest_t4 and t6
(1 row)
QUERY: select * from rtest_t7;
a|b
--+-----------------------------------
19|Record should go to rtest_t5 and t7
(1 row)
QUERY: select * from rtest_t8;
a|b
--+-----------------------------------
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
(2 rows)
QUERY: delete from rtest_t4;
QUERY: delete from rtest_t5;
QUERY: delete from rtest_t6;
QUERY: delete from rtest_t7;
QUERY: delete from rtest_t8;
QUERY: insert into rtest_t9 values (1, 'Record should go to rtest_t4');
QUERY: insert into rtest_t9 values (2, 'Record should go to rtest_t4');
QUERY: insert into rtest_t9 values (10, 'Record should go to rtest_t5');
QUERY: insert into rtest_t9 values (15, 'Record should go to rtest_t5');
QUERY: insert into rtest_t9 values (19, 'Record should go to rtest_t5 and t7');
QUERY: insert into rtest_t9 values (20, 'Record should go to rtest_t4 and t6');
QUERY: insert into rtest_t9 values (26, 'Record should go to rtest_t4 and t8');
QUERY: insert into rtest_t9 values (28, 'Record should go to rtest_t4 and t8');
QUERY: insert into rtest_t9 values (30, 'Record should go to rtest_t4');
QUERY: insert into rtest_t9 values (40, 'Record should go to rtest_t4');
QUERY: insert into rtest_t4 select * from rtest_t9 where a < 20;
QUERY: select * from rtest_t4;
a|b
-+----------------------------
1|Record should go to rtest_t4
2|Record should go to rtest_t4
(2 rows)
QUERY: select * from rtest_t5;
a|b
--+-----------------------------------
10|Record should go to rtest_t5
15|Record should go to rtest_t5
19|Record should go to rtest_t5 and t7
(3 rows)
QUERY: select * from rtest_t6;
a|b
-+-
(0 rows)
QUERY: select * from rtest_t7;
a|b
--+-----------------------------------
19|Record should go to rtest_t5 and t7
(1 row)
QUERY: select * from rtest_t8;
a|b
-+-
(0 rows)
QUERY: insert into rtest_t4 select * from rtest_t9 where b ~ 'and t8';
QUERY: select * from rtest_t4;
a|b
--+-----------------------------------
1|Record should go to rtest_t4
2|Record should go to rtest_t4
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
(4 rows)
QUERY: select * from rtest_t5;
a|b
--+-----------------------------------
10|Record should go to rtest_t5
15|Record should go to rtest_t5
19|Record should go to rtest_t5 and t7
(3 rows)
QUERY: select * from rtest_t6;
a|b
-+-
(0 rows)
QUERY: select * from rtest_t7;
a|b
--+-----------------------------------
19|Record should go to rtest_t5 and t7
(1 row)
QUERY: select * from rtest_t8;
a|b
--+-----------------------------------
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
(2 rows)
QUERY: insert into rtest_t4 select a + 1, b from rtest_t9 where a in (20, 30, 40);
QUERY: select * from rtest_t4;
a|b
--+-----------------------------------
1|Record should go to rtest_t4
2|Record should go to rtest_t4
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
21|Record should go to rtest_t4 and t6
31|Record should go to rtest_t4
41|Record should go to rtest_t4
(7 rows)
QUERY: select * from rtest_t5;
a|b
--+-----------------------------------
10|Record should go to rtest_t5
15|Record should go to rtest_t5
19|Record should go to rtest_t5 and t7
(3 rows)
QUERY: select * from rtest_t6;
a|b
--+-----------------------------------
21|Record should go to rtest_t4 and t6
(1 row)
QUERY: select * from rtest_t7;
a|b
--+-----------------------------------
19|Record should go to rtest_t5 and t7
(1 row)
QUERY: select * from rtest_t8;
a|b
--+-----------------------------------
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
(2 rows)
QUERY: insert into rtest_order1 values (1);
QUERY: select * from rtest_order2;
a|b|c
-+-+-----------------------------------
1|1|rule 2 - this should run 1st
1|2|rule 4 - this should run 2nd
1|3|rule 3 - this should run 3rd or 4th
1|4|rule 1 - this should run 3rd or 4th
(4 rows)
QUERY: insert into rtest_nothn1 values (1, 'want this');
QUERY: insert into rtest_nothn1 values (2, 'want this');
QUERY: insert into rtest_nothn1 values (10, 'don''t want this');
QUERY: insert into rtest_nothn1 values (19, 'don''t want this');
QUERY: insert into rtest_nothn1 values (20, 'want this');
QUERY: insert into rtest_nothn1 values (29, 'want this');
QUERY: insert into rtest_nothn1 values (30, 'don''t want this');
QUERY: insert into rtest_nothn1 values (39, 'don''t want this');
QUERY: insert into rtest_nothn1 values (40, 'want this');
QUERY: insert into rtest_nothn1 values (50, 'want this');
QUERY: insert into rtest_nothn1 values (60, 'want this');
QUERY: select * from rtest_nothn1;
a|b
--+---------
1|want this
2|want this
20|want this
29|want this
40|want this
50|want this
60|want this
(7 rows)
QUERY: insert into rtest_nothn2 values (10, 'too small');
QUERY: insert into rtest_nothn2 values (50, 'too small');
QUERY: insert into rtest_nothn2 values (100, 'OK');
QUERY: insert into rtest_nothn2 values (200, 'OK');
QUERY: select * from rtest_nothn2;
a|b
-+-
(0 rows)
QUERY: select * from rtest_nothn3;
a|b
---+--
100|OK
200|OK
(2 rows)
QUERY: delete from rtest_nothn1;
QUERY: delete from rtest_nothn2;
QUERY: delete from rtest_nothn3;
QUERY: insert into rtest_nothn4 values (1, 'want this');
QUERY: insert into rtest_nothn4 values (2, 'want this');
QUERY: insert into rtest_nothn4 values (10, 'don''t want this');
QUERY: insert into rtest_nothn4 values (19, 'don''t want this');
QUERY: insert into rtest_nothn4 values (20, 'want this');
QUERY: insert into rtest_nothn4 values (29, 'want this');
QUERY: insert into rtest_nothn4 values (30, 'don''t want this');
QUERY: insert into rtest_nothn4 values (39, 'don''t want this');
QUERY: insert into rtest_nothn4 values (40, 'want this');
QUERY: insert into rtest_nothn4 values (50, 'want this');
QUERY: insert into rtest_nothn4 values (60, 'want this');
QUERY: insert into rtest_nothn1 select * from rtest_nothn4;
QUERY: select * from rtest_nothn1;
a|b
--+---------
1|want this
2|want this
20|want this
29|want this
40|want this
50|want this
60|want this
(7 rows)
QUERY: delete from rtest_nothn4;
QUERY: insert into rtest_nothn4 values (10, 'too small');
QUERY: insert into rtest_nothn4 values (50, 'too small');
QUERY: insert into rtest_nothn4 values (100, 'OK');
QUERY: insert into rtest_nothn4 values (200, 'OK');
QUERY: insert into rtest_nothn2 select * from rtest_nothn4;
QUERY: select * from rtest_nothn2;
a|b
-+-
(0 rows)
QUERY: select * from rtest_nothn3;
a|b
---+--
100|OK
200|OK
(2 rows)
QUERY: create table rtest_view1 (a int4, b text, v bool);
QUERY: create table rtest_view2 (a int4);
QUERY: create table rtest_view3 (a int4, b text);
QUERY: create table rtest_view4 (a int4, b text, c int4);
QUERY: create view rtest_vview1 as select a, b from rtest_view1 X
where 0 < (select count(*) from rtest_view2 Y where Y.a = X.a);
QUERY: create view rtest_vview2 as select a, b from rtest_view1 where v;
QUERY: create view rtest_vview3 as select a, b from rtest_vview2 X
where 0 < (select count(*) from rtest_view2 Y where Y.a = X.a);
QUERY: create view rtest_vview4 as select X.a, X.b, count(Y.a) as refcount
from rtest_view1 X, rtest_view2 Y
where X.a = Y.a
group by X.a, X.b;
QUERY: create function rtest_viewfunc1(int4) returns int4 as
'select count(*) from rtest_view2 where a = $1'
language 'sql';
QUERY: create view rtest_vview5 as select a, b, rtest_viewfunc1(a) as refcount
from rtest_view1;
QUERY: insert into rtest_view1 values (1, 'item 1', 't');
QUERY: insert into rtest_view1 values (2, 'item 2', 't');
QUERY: insert into rtest_view1 values (3, 'item 3', 't');
QUERY: insert into rtest_view1 values (4, 'item 4', 'f');
QUERY: insert into rtest_view1 values (5, 'item 5', 't');
QUERY: insert into rtest_view1 values (6, 'item 6', 'f');
QUERY: insert into rtest_view1 values (7, 'item 7', 't');
QUERY: insert into rtest_view1 values (8, 'item 8', 't');
QUERY: insert into rtest_view2 values (2);
QUERY: insert into rtest_view2 values (2);
QUERY: insert into rtest_view2 values (4);
QUERY: insert into rtest_view2 values (5);
QUERY: insert into rtest_view2 values (7);
QUERY: insert into rtest_view2 values (7);
QUERY: insert into rtest_view2 values (7);
QUERY: insert into rtest_view2 values (7);
QUERY: select * from rtest_vview1;
a|b
-+------
2|item 2
4|item 4
5|item 5
7|item 7
(4 rows)
QUERY: select * from rtest_vview2;
a|b
-+------
1|item 1
2|item 2
3|item 3
5|item 5
7|item 7
8|item 8
(6 rows)
QUERY: select * from rtest_vview3;
a|b
-+------
2|item 2
5|item 5
7|item 7
(3 rows)
QUERY: select * from rtest_vview4;
a|b |refcount
-+------+--------
2|item 2| 2
4|item 4| 1
5|item 5| 1
7|item 7| 4
(4 rows)
QUERY: select * from rtest_vview5;
a|b |refcount
-+------+--------
1|item 1| 0
2|item 2| 2
3|item 3| 0
4|item 4| 1
5|item 5| 1
6|item 6| 0
7|item 7| 4
8|item 8| 0
(8 rows)
QUERY: insert into rtest_view3 select * from rtest_vview1 where a < 7;
QUERY: select * from rtest_view3;
a|b
-+------
2|item 2
4|item 4
5|item 5
(3 rows)
QUERY: delete from rtest_view3;
QUERY: insert into rtest_view3 select * from rtest_vview2 where a != 5 and b !~ '2';
QUERY: select * from rtest_view3;
a|b
-+------
1|item 1
3|item 3
7|item 7
8|item 8
(4 rows)
QUERY: delete from rtest_view3;
QUERY: insert into rtest_view3 select * from rtest_vview3;
QUERY: select * from rtest_view3;
a|b
-+------
2|item 2
5|item 5
7|item 7
(3 rows)
QUERY: delete from rtest_view3;
QUERY: insert into rtest_view4 select * from rtest_vview4 where 3 > refcount;
QUERY: select * from rtest_view4;
a|b |c
-+------+-
2|item 2|2
4|item 4|1
5|item 5|1
(3 rows)
QUERY: delete from rtest_view4;
QUERY: insert into rtest_view4 select * from rtest_vview5 where a > 2 and refcount = 0;
QUERY: select * from rtest_view4;
a|b |c
-+------+-
3|item 3|0
6|item 6|0
8|item 8|0
(3 rows)
QUERY: delete from rtest_view4;
QUERY: create table rtest_comp (
part text,
unit char(4),
size float
);
QUERY: create table rtest_unitfact (
unit char(4),
factor float
);
QUERY: create view rtest_vcomp as
select X.part, (X.size * Y.factor) as size_in_cm
from rtest_comp X, rtest_unitfact Y
where X.unit = Y.unit;
QUERY: insert into rtest_unitfact values ('m', 100.0);
QUERY: insert into rtest_unitfact values ('cm', 1.0);
QUERY: insert into rtest_unitfact values ('inch', 2.54);
QUERY: insert into rtest_comp values ('p1', 'm', 5.0);
QUERY: insert into rtest_comp values ('p2', 'm', 3.0);
QUERY: insert into rtest_comp values ('p3', 'cm', 5.0);
QUERY: insert into rtest_comp values ('p4', 'cm', 15.0);
QUERY: insert into rtest_comp values ('p5', 'inch', 7.0);
QUERY: insert into rtest_comp values ('p6', 'inch', 4.4);
QUERY: select * from rtest_vcomp order by part;
part|size_in_cm
----+----------
p1 | 500
p2 | 300
p3 | 5
p4 | 15
p5 | 17.78
p6 | 11.176
(6 rows)
QUERY: select * from rtest_vcomp where size_in_cm > 10.0 order by size_in_cm using >;
part|size_in_cm
----+----------
p1 | 500
p2 | 300
p5 | 17.78
p4 | 15
p6 | 11.176
(5 rows)
QUERY: CREATE TABLE shoe_data (
shoename char(10),
sh_avail integer,
slcolor char(10),
slminlen float,
slmaxlen float,
slunit char(8)
);
QUERY: CREATE TABLE shoelace_data (
sl_name char(10),
sl_avail integer,
sl_color char(10),
sl_len float,
sl_unit char(8)
);
QUERY: CREATE TABLE unit (
un_name char(8),
un_fact float
);
QUERY: CREATE VIEW shoe AS
SELECT sh.shoename,
sh.sh_avail,
sh.slcolor,
sh.slminlen,
sh.slminlen * un.un_fact AS slminlen_cm,
sh.slmaxlen,
sh.slmaxlen * un.un_fact AS slmaxlen_cm,
sh.slunit
FROM shoe_data sh, unit un
WHERE sh.slunit = un.un_name;
QUERY: CREATE VIEW shoelace AS
SELECT s.sl_name,
s.sl_avail,
s.sl_color,
s.sl_len,
s.sl_unit,
s.sl_len * u.un_fact AS sl_len_cm
FROM shoelace_data s, unit u
WHERE s.sl_unit = u.un_name;
QUERY: CREATE VIEW shoe_ready AS
SELECT rsh.shoename,
rsh.sh_avail,
rsl.sl_name,
rsl.sl_avail,
int4smaller(rsh.sh_avail, rsl.sl_avail) AS total_avail
FROM shoe rsh, shoelace rsl
WHERE rsl.sl_color = rsh.slcolor
AND rsl.sl_len_cm >= rsh.slminlen_cm
AND rsl.sl_len_cm <= rsh.slmaxlen_cm;
QUERY: INSERT INTO unit VALUES ('cm', 1.0);
QUERY: INSERT INTO unit VALUES ('m', 100.0);
QUERY: INSERT INTO unit VALUES ('inch', 2.54);
QUERY: INSERT INTO shoe_data VALUES ('sh1', 2, 'black', 70.0, 90.0, 'cm');
QUERY: INSERT INTO shoe_data VALUES ('sh2', 0, 'black', 30.0, 40.0, 'inch');
QUERY: INSERT INTO shoe_data VALUES ('sh3', 4, 'brown', 50.0, 65.0, 'cm');
QUERY: INSERT INTO shoe_data VALUES ('sh4', 3, 'brown', 40.0, 50.0, 'inch');
QUERY: INSERT INTO shoelace_data VALUES ('sl1', 5, 'black', 80.0, 'cm');
QUERY: INSERT INTO shoelace_data VALUES ('sl2', 6, 'black', 100.0, 'cm');
QUERY: INSERT INTO shoelace_data VALUES ('sl3', 0, 'black', 35.0 , 'inch');
QUERY: INSERT INTO shoelace_data VALUES ('sl4', 8, 'black', 40.0 , 'inch');
QUERY: INSERT INTO shoelace_data VALUES ('sl5', 4, 'brown', 1.0 , 'm');
QUERY: INSERT INTO shoelace_data VALUES ('sl6', 0, 'brown', 0.9 , 'm');
QUERY: INSERT INTO shoelace_data VALUES ('sl7', 7, 'brown', 60 , 'cm');
QUERY: INSERT INTO shoelace_data VALUES ('sl8', 1, 'brown', 40 , 'inch');
QUERY: SELECT * FROM shoelace;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm
----------+--------+----------+------+--------+---------
sl1 | 5|black | 80|cm | 80
sl2 | 6|black | 100|cm | 100
sl7 | 7|brown | 60|cm | 60
sl3 | 0|black | 35|inch | 88.9
sl4 | 8|black | 40|inch | 101.6
sl8 | 1|brown | 40|inch | 101.6
sl5 | 4|brown | 1|m | 100
sl6 | 0|brown | 0.9|m | 90
(8 rows)
QUERY: SELECT * FROM shoe_ready WHERE total_avail >= 2;
shoename |sh_avail|sl_name |sl_avail|total_avail
----------+--------+----------+--------+-----------
sh1 | 2|sl1 | 5| 2
sh3 | 4|sl7 | 7| 4
(2 rows)
QUERY: CREATE TABLE shoelace_log (
sl_name char(10),
sl_avail integer,
log_who name,
log_when datetime
);
QUERY: CREATE RULE log_shoelace AS ON UPDATE TO shoelace_data
WHERE NEW.sl_avail != OLD.sl_avail
DO INSERT INTO shoelace_log VALUES (
NEW.sl_name,
NEW.sl_avail,
getpgusername(),
'epoch'::text
);
QUERY: UPDATE shoelace_data SET sl_avail = 6 WHERE sl_name = 'sl7';
QUERY: SELECT * FROM shoelace_log;
sl_name |sl_avail|log_who|log_when
----------+--------+-------+--------
1999-02-22 03:06:38 +01:00
sl7 | 6|postgres|epoch
(1 row)
QUERY: CREATE RULE shoelace_ins AS ON INSERT TO shoelace
DO INSTEAD
INSERT INTO shoelace_data VALUES (
NEW.sl_name,
NEW.sl_avail,
NEW.sl_color,
NEW.sl_len,
NEW.sl_unit);
QUERY: CREATE RULE shoelace_upd AS ON UPDATE TO shoelace
DO INSTEAD
UPDATE shoelace_data SET
sl_name = NEW.sl_name,
sl_avail = NEW.sl_avail,
sl_color = NEW.sl_color,
sl_len = NEW.sl_len,
sl_unit = NEW.sl_unit
WHERE sl_name = OLD.sl_name;
QUERY: CREATE RULE shoelace_del AS ON DELETE TO shoelace
DO INSTEAD
DELETE FROM shoelace_data
WHERE sl_name = OLD.sl_name;
QUERY: CREATE TABLE shoelace_arrive (
arr_name char(10),
arr_quant integer
);
QUERY: CREATE TABLE shoelace_ok (
ok_name char(10),
ok_quant integer
);
QUERY: CREATE RULE shoelace_ok_ins AS ON INSERT TO shoelace_ok
DO INSTEAD
UPDATE shoelace SET
sl_avail = sl_avail + NEW.ok_quant
WHERE sl_name = NEW.ok_name;
QUERY: INSERT INTO shoelace_arrive VALUES ('sl3', 10);
QUERY: INSERT INTO shoelace_arrive VALUES ('sl6', 20);
QUERY: INSERT INTO shoelace_arrive VALUES ('sl8', 20);
QUERY: SELECT * FROM shoelace;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm
----------+--------+----------+------+--------+---------
sl1 | 5|black | 80|cm | 80
sl2 | 6|black | 100|cm | 100
sl7 | 6|brown | 60|cm | 60
sl3 | 0|black | 35|inch | 88.9
sl4 | 8|black | 40|inch | 101.6
sl8 | 1|brown | 40|inch | 101.6
sl5 | 4|brown | 1|m | 100
sl6 | 0|brown | 0.9|m | 90
(8 rows)
QUERY: insert into shoelace_ok select * from shoelace_arrive;
QUERY: SELECT * FROM shoelace;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm
----------+--------+----------+------+--------+---------
sl1 | 5|black | 80|cm | 80
sl2 | 6|black | 100|cm | 100
sl7 | 6|brown | 60|cm | 60
sl4 | 8|black | 40|inch | 101.6
sl3 | 10|black | 35|inch | 88.9
sl8 | 21|brown | 40|inch | 101.6
sl5 | 4|brown | 1|m | 100
sl6 | 20|brown | 0.9|m | 90
(8 rows)
QUERY: SELECT * FROM shoelace_log;
sl_name |sl_avail|log_who|log_when
----------+--------+-------+--------
1999-02-22 03:06:38 +01:00
sl7 | 6|postgres|epoch
sl3 | 10|postgres|epoch
sl6 | 20|postgres|epoch
sl8 | 21|postgres|epoch
(4 rows)
QUERY: CREATE VIEW shoelace_obsolete AS
SELECT * FROM shoelace WHERE NOT EXISTS
(SELECT shoename FROM shoe WHERE slcolor = sl_color);
QUERY: CREATE VIEW shoelace_candelete AS
SELECT * FROM shoelace_obsolete WHERE sl_avail = 0;
QUERY: insert into shoelace values ('sl9', 0, 'pink', 35.0, 'inch', 0.0);
QUERY: insert into shoelace values ('sl10', 1000, 'magenta', 40.0, 'inch', 0.0);
QUERY: SELECT * FROM shoelace_obsolete;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm
----------+--------+----------+------+--------+---------
sl9 | 0|pink | 35|inch | 88.9
sl10 | 1000|magenta | 40|inch | 101.6
(2 rows)
QUERY: SELECT * FROM shoelace_candelete;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm
----------+--------+----------+------+--------+---------
sl9 | 0|pink | 35|inch | 88.9
(1 row)
QUERY: DELETE FROM shoelace WHERE EXISTS
(SELECT * FROM shoelace_candelete
WHERE sl_name = shoelace.sl_name);
QUERY: SELECT * FROM shoelace;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm
----------+--------+----------+------+--------+---------
sl1 | 5|black | 80|cm | 80
sl2 | 6|black | 100|cm | 100
sl7 | 6|brown | 60|cm | 60
sl4 | 8|black | 40|inch | 101.6
sl3 | 10|black | 35|inch | 88.9
sl8 | 21|brown | 40|inch | 101.6
sl10 | 1000|magenta | 40|inch | 101.6
sl5 | 4|brown | 1|m | 100
sl6 | 20|brown | 0.9|m | 90
(9 rows)