Commit 260b6afc authored by Tom Lane's avatar Tom Lane

Update remaining tests for new psql, with the exception of 'arrays',

which is broken in some weird way that I don't understand.  I think it
may be exposing a bug in the new psql --- for one thing, I get different
results when I run psql by hand than the regress script gets.  What
the heck???
parent 0e821fb7
QUERY: SELECT avg(four) AS avg_1 FROM onek; --
avg_1 -- AGGREGATES
----- --
1 SELECT avg(four) AS avg_1 FROM onek;
avg_1
-------
1
(1 row) (1 row)
QUERY: SELECT avg(a) AS avg_32 FROM aggtest WHERE a < 100; SELECT avg(a) AS avg_32 FROM aggtest WHERE a < 100;
avg_32 avg_32
------ --------
32 32
(1 row) (1 row)
QUERY: SELECT avg(b) AS avg_107_943 FROM aggtest; SELECT avg(b) AS avg_107_943 FROM aggtest;
avg_107_943 avg_107_943
----------- -------------
107.943 107.943
(1 row) (1 row)
QUERY: SELECT avg(gpa) AS avg_3_4 FROM student; SELECT avg(gpa) AS avg_3_4 FROM student;
avg_3_4 avg_3_4
------- ---------
3.4 3.4
(1 row) (1 row)
QUERY: SELECT sum(four) AS sum_1500 FROM onek; SELECT sum(four) AS sum_1500 FROM onek;
sum_1500 sum_1500
-------- ----------
1500 1500
(1 row) (1 row)
QUERY: SELECT sum(a) AS sum_198 FROM aggtest; SELECT sum(a) AS sum_198 FROM aggtest;
sum_198 sum_198
------- ---------
198 198
(1 row)
SELECT sum(b) AS avg_431_773 FROM aggtest;
avg_431_773
-------------
431.773
(1 row) (1 row)
QUERY: SELECT sum(b) AS avg_431_773 FROM aggtest; SELECT sum(gpa) AS avg_6_8 FROM student;
avg_431_773 avg_6_8
----------- ---------
431.773 6.8
(1 row) (1 row)
QUERY: SELECT sum(gpa) AS avg_6_8 FROM student; SELECT max(four) AS max_3 FROM onek;
avg_6_8 max_3
------- -------
6.8 3
(1 row) (1 row)
QUERY: SELECT max(four) AS max_3 FROM onek; SELECT max(a) AS max_100 FROM aggtest;
max_3 max_100
----- ---------
3 100
(1 row) (1 row)
QUERY: SELECT max(a) AS max_100 FROM aggtest; SELECT max(aggtest.b) AS max_324_78 FROM aggtest;
max_100 max_324_78
------- ------------
100 324.78
(1 row) (1 row)
QUERY: SELECT max(aggtest.b) AS max_324_78 FROM aggtest; SELECT max(student.gpa) AS max_3_7 FROM student;
max_324_78 max_3_7
---------- ---------
324.78 3.7
(1 row) (1 row)
QUERY: SELECT max(student.gpa) AS max_3_7 FROM student; SELECT count(four) AS cnt_1000 FROM onek;
max_3_7 cnt_1000
------- ----------
3.7 1000
(1 row) (1 row)
QUERY: SELECT count(four) AS cnt_1000 FROM onek; SELECT count(DISTINCT four) AS cnt_4 FROM onek;
cnt_1000 cnt_4
-------- -------
1000 4
(1 row) (1 row)
QUERY: SELECT count(DISTINCT four) AS cnt_4 FROM onek; select ten, count(*), sum(four) from onek group by ten;
cnt_4 ten | count | sum
----- -----+-------+-----
4 0 | 100 | 100
(1 row) 1 | 100 | 200
2 | 100 | 100
QUERY: select ten, count(*), sum(four) from onek group by ten; 3 | 100 | 200
ten|count|sum 4 | 100 | 100
---+-----+--- 5 | 100 | 200
0| 100|100 6 | 100 | 100
1| 100|200 7 | 100 | 200
2| 100|100 8 | 100 | 100
3| 100|200 9 | 100 | 200
4| 100|100
5| 100|200
6| 100|100
7| 100|200
8| 100|100
9| 100|200
(10 rows) (10 rows)
QUERY: select ten, count(four), sum(DISTINCT four) from onek group by ten; select ten, count(four), sum(DISTINCT four) from onek group by ten;
ten|count|sum ten | count | sum
---+-----+--- -----+-------+-----
0| 100| 2 0 | 100 | 2
1| 100| 4 1 | 100 | 4
2| 100| 2 2 | 100 | 2
3| 100| 4 3 | 100 | 4
4| 100| 2 4 | 100 | 2
5| 100| 4 5 | 100 | 4
6| 100| 2 6 | 100 | 2
7| 100| 4 7 | 100 | 4
8| 100| 2 8 | 100 | 2
9| 100| 4 9 | 100 | 4
(10 rows) (10 rows)
QUERY: SELECT newavg(four) AS avg_1 FROM onek; SELECT newavg(four) AS avg_1 FROM onek;
avg_1 avg_1
----- -------
1 1
(1 row) (1 row)
QUERY: SELECT newsum(four) AS sum_1500 FROM onek; SELECT newsum(four) AS sum_1500 FROM onek;
sum_1500 sum_1500
-------- ----------
1500 1500
(1 row) (1 row)
QUERY: SELECT newcnt(four) AS cnt_1000 FROM onek; SELECT newcnt(four) AS cnt_1000 FROM onek;
cnt_1000 cnt_1000
-------- ----------
1000 1000
(1 row) (1 row)
QUERY: CREATE TABLE tmp (initial int4); --
QUERY: ALTER TABLE tmp ADD COLUMN a int4; -- ALTER_TABLE
QUERY: ALTER TABLE tmp ADD COLUMN b name; -- add attribute
QUERY: ALTER TABLE tmp ADD COLUMN c text; --
QUERY: ALTER TABLE tmp ADD COLUMN d float8; CREATE TABLE tmp (initial int4);
QUERY: ALTER TABLE tmp ADD COLUMN e float4; ALTER TABLE tmp ADD COLUMN a int4;
QUERY: ALTER TABLE tmp ADD COLUMN f int2; ALTER TABLE tmp ADD COLUMN b name;
QUERY: ALTER TABLE tmp ADD COLUMN g polygon; ALTER TABLE tmp ADD COLUMN c text;
QUERY: ALTER TABLE tmp ADD COLUMN h abstime; ALTER TABLE tmp ADD COLUMN d float8;
QUERY: ALTER TABLE tmp ADD COLUMN i char; ALTER TABLE tmp ADD COLUMN e float4;
QUERY: ALTER TABLE tmp ADD COLUMN j abstime[]; ALTER TABLE tmp ADD COLUMN f int2;
QUERY: ALTER TABLE tmp ADD COLUMN k dt; ALTER TABLE tmp ADD COLUMN g polygon;
ALTER TABLE tmp ADD COLUMN h abstime;
ALTER TABLE tmp ADD COLUMN i char;
ALTER TABLE tmp ADD COLUMN j abstime[];
ALTER TABLE tmp ADD COLUMN k dt;
ERROR: Unable to locate type name 'dt' in catalog ERROR: Unable to locate type name 'dt' in catalog
QUERY: ALTER TABLE tmp ADD COLUMN l tid; ALTER TABLE tmp ADD COLUMN l tid;
QUERY: ALTER TABLE tmp ADD COLUMN m xid; ALTER TABLE tmp ADD COLUMN m xid;
QUERY: ALTER TABLE tmp ADD COLUMN n oid8; ALTER TABLE tmp ADD COLUMN n oid8;
QUERY: ALTER TABLE tmp ADD COLUMN p smgr; --ALTER TABLE tmp ADD COLUMN o lock;
QUERY: ALTER TABLE tmp ADD COLUMN q point; ALTER TABLE tmp ADD COLUMN p smgr;
QUERY: ALTER TABLE tmp ADD COLUMN r lseg; ALTER TABLE tmp ADD COLUMN q point;
QUERY: ALTER TABLE tmp ADD COLUMN s path; ALTER TABLE tmp ADD COLUMN r lseg;
QUERY: ALTER TABLE tmp ADD COLUMN t box; ALTER TABLE tmp ADD COLUMN s path;
QUERY: ALTER TABLE tmp ADD COLUMN u tinterval; ALTER TABLE tmp ADD COLUMN t box;
QUERY: ALTER TABLE tmp ADD COLUMN v datetime; ALTER TABLE tmp ADD COLUMN u tinterval;
QUERY: ALTER TABLE tmp ADD COLUMN w timespan; ALTER TABLE tmp ADD COLUMN v datetime;
QUERY: ALTER TABLE tmp ADD COLUMN x float8[]; ALTER TABLE tmp ADD COLUMN w timespan;
QUERY: ALTER TABLE tmp ADD COLUMN y float4[]; ALTER TABLE tmp ADD COLUMN x float8[];
QUERY: ALTER TABLE tmp ADD COLUMN z int2[]; ALTER TABLE tmp ADD COLUMN y float4[];
QUERY: INSERT INTO tmp (a, b, c, d, e, f, g, h, i, j, k, l, m, n, p, q, r, s, t, u, ALTER TABLE tmp ADD COLUMN z int2[];
INSERT INTO tmp (a, b, c, d, e, f, g, h, i, j, k, l, m, n, p, q, r, s, t, u,
v, w, x, y, z) v, w, x, y, z)
VALUES (4, 'name', 'text', 4.1, 4.1, 2, '(4.1,4.1,3.1,3.1)', VALUES (4, 'name', 'text', 4.1, 4.1, 2, '(4.1,4.1,3.1,3.1)',
'Mon May 1 00:30:30 1995', 'c', '{Mon May 1 00:30:30 1995, Monday Aug 24 14:43:07 1992, epoch}', 'Mon May 1 00:30:30 1995', 'c', '{Mon May 1 00:30:30 1995, Monday Aug 24 14:43:07 1992, epoch}',
314159, '(1,1)', 512, 314159, '(1,1)', 512,
'1 2 3 4 5 6 7 8', 'magnetic disk', '(1.1,1.1)', '(4.1,4.1,3.1,3.1)', '1 2 3 4 5 6 7 8', 'magnetic disk', '(1.1,1.1)', '(4.1,4.1,3.1,3.1)',
'(0,2,4.1,4.1,3.1,3.1)', '(4.1,4.1,3.1,3.1)', '["current" "infinity"]', '(0,2,4.1,4.1,3.1,3.1)', '(4.1,4.1,3.1,3.1)', '["current" "infinity"]',
'1/3', '1,name', '{1.0,2.0,3.0,4.0}', '{1.0,2.0,3.0,4.0}', '{1,2,3,4}'); '1/3', '1,name', '{1.0,2.0,3.0,4.0}', '{1.0,2.0,3.0,4.0}', '{1,2,3,4}');
ERROR: Relation 'tmp' does not have attribute 'k' ERROR: Relation 'tmp' does not have attribute 'k'
QUERY: SELECT * FROM tmp; SELECT * FROM tmp;
initial|a|b|c|d|e|f|g|h|i|j|l|m|n|p|q|r|s|t|u|v|w|x|y|z initial | a | b | c | d | e | f | g | h | i | j | l | m | n | p | q | r | s | t | u | v | w | x | y | z
-------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- ---------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
(0 rows) (0 rows)
QUERY: DROP TABLE tmp; DROP TABLE tmp;
QUERY: CREATE TABLE tmp ( -- the wolf bug - schema mods caused inconsistent row descriptors
CREATE TABLE tmp (
initial int4 initial int4
); );
QUERY: ALTER TABLE tmp ADD COLUMN a int4; ALTER TABLE tmp ADD COLUMN a int4;
QUERY: ALTER TABLE tmp ADD COLUMN b name; ALTER TABLE tmp ADD COLUMN b name;
QUERY: ALTER TABLE tmp ADD COLUMN c text; ALTER TABLE tmp ADD COLUMN c text;
QUERY: ALTER TABLE tmp ADD COLUMN d float8; ALTER TABLE tmp ADD COLUMN d float8;
QUERY: ALTER TABLE tmp ADD COLUMN e float4; ALTER TABLE tmp ADD COLUMN e float4;
QUERY: ALTER TABLE tmp ADD COLUMN f int2; ALTER TABLE tmp ADD COLUMN f int2;
QUERY: ALTER TABLE tmp ADD COLUMN g polygon; ALTER TABLE tmp ADD COLUMN g polygon;
QUERY: ALTER TABLE tmp ADD COLUMN h abstime; ALTER TABLE tmp ADD COLUMN h abstime;
QUERY: ALTER TABLE tmp ADD COLUMN i char; ALTER TABLE tmp ADD COLUMN i char;
QUERY: ALTER TABLE tmp ADD COLUMN j abstime[]; ALTER TABLE tmp ADD COLUMN j abstime[];
QUERY: ALTER TABLE tmp ADD COLUMN k dt; ALTER TABLE tmp ADD COLUMN k dt;
ERROR: Unable to locate type name 'dt' in catalog ERROR: Unable to locate type name 'dt' in catalog
QUERY: ALTER TABLE tmp ADD COLUMN l tid; ALTER TABLE tmp ADD COLUMN l tid;
QUERY: ALTER TABLE tmp ADD COLUMN m xid; ALTER TABLE tmp ADD COLUMN m xid;
QUERY: ALTER TABLE tmp ADD COLUMN n oid8; ALTER TABLE tmp ADD COLUMN n oid8;
QUERY: ALTER TABLE tmp ADD COLUMN p smgr; --ALTER TABLE tmp ADD COLUMN o lock;
QUERY: ALTER TABLE tmp ADD COLUMN q point; ALTER TABLE tmp ADD COLUMN p smgr;
QUERY: ALTER TABLE tmp ADD COLUMN r lseg; ALTER TABLE tmp ADD COLUMN q point;
QUERY: ALTER TABLE tmp ADD COLUMN s path; ALTER TABLE tmp ADD COLUMN r lseg;
QUERY: ALTER TABLE tmp ADD COLUMN t box; ALTER TABLE tmp ADD COLUMN s path;
QUERY: ALTER TABLE tmp ADD COLUMN u tinterval; ALTER TABLE tmp ADD COLUMN t box;
QUERY: ALTER TABLE tmp ADD COLUMN v datetime; ALTER TABLE tmp ADD COLUMN u tinterval;
QUERY: ALTER TABLE tmp ADD COLUMN w timespan; ALTER TABLE tmp ADD COLUMN v datetime;
QUERY: ALTER TABLE tmp ADD COLUMN x float8[]; ALTER TABLE tmp ADD COLUMN w timespan;
QUERY: ALTER TABLE tmp ADD COLUMN y float4[]; ALTER TABLE tmp ADD COLUMN x float8[];
QUERY: ALTER TABLE tmp ADD COLUMN z int2[]; ALTER TABLE tmp ADD COLUMN y float4[];
QUERY: INSERT INTO tmp (a, b, c, d, e, f, g, h, i, j, k, l, m, n, p, q, r, s, t, u, ALTER TABLE tmp ADD COLUMN z int2[];
INSERT INTO tmp (a, b, c, d, e, f, g, h, i, j, k, l, m, n, p, q, r, s, t, u,
v, w, x, y, z) v, w, x, y, z)
VALUES (4, 'name', 'text', 4.1, 4.1, 2, '(4.1,4.1,3.1,3.1)', VALUES (4, 'name', 'text', 4.1, 4.1, 2, '(4.1,4.1,3.1,3.1)',
'Mon May 1 00:30:30 1995', 'c', '{Mon May 1 00:30:30 1995, Monday Aug 24 14:43:07 1992, epoch}', 'Mon May 1 00:30:30 1995', 'c', '{Mon May 1 00:30:30 1995, Monday Aug 24 14:43:07 1992, epoch}',
314159, '(1,1)', 512, 314159, '(1,1)', 512,
'1 2 3 4 5 6 7 8', 'magnetic disk', '(1.1,1.1)', '(4.1,4.1,3.1,3.1)', '1 2 3 4 5 6 7 8', 'magnetic disk', '(1.1,1.1)', '(4.1,4.1,3.1,3.1)',
'(0,2,4.1,4.1,3.1,3.1)', '(4.1,4.1,3.1,3.1)', '["current" "infinity"]', '(0,2,4.1,4.1,3.1,3.1)', '(4.1,4.1,3.1,3.1)', '["current" "infinity"]',
'1/3', '1,name', '{1.0,2.0,3.0,4.0}', '{1.0,2.0,3.0,4.0}', '{1,2,3,4}'); '1/3', '1,name', '{1.0,2.0,3.0,4.0}', '{1.0,2.0,3.0,4.0}', '{1,2,3,4}');
ERROR: Relation 'tmp' does not have attribute 'k' ERROR: Relation 'tmp' does not have attribute 'k'
QUERY: SELECT * FROM tmp; SELECT * FROM tmp;
initial|a|b|c|d|e|f|g|h|i|j|l|m|n|p|q|r|s|t|u|v|w|x|y|z initial | a | b | c | d | e | f | g | h | i | j | l | m | n | p | q | r | s | t | u | v | w | x | y | z
-------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- ---------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
(0 rows) (0 rows)
QUERY: DROP TABLE tmp; DROP TABLE tmp;
QUERY: ALTER TABLE tenk1 RENAME TO ten_k; --
QUERY: SELECT unique1 FROM ten_k WHERE unique1 < 20; -- rename -
unique1 -- should preserve indices
------- --
0 ALTER TABLE tenk1 RENAME TO ten_k;
1 -- 20 values, sorted
2 SELECT unique1 FROM ten_k WHERE unique1 < 20;
3 unique1
4 ---------
5 0
6 1
7 2
8 3
9 4
10 5
11 6
12 7
13 8
14 9
15 10
16 11
17 12
18 13
19 14
15
16
17
18
19
(20 rows) (20 rows)
QUERY: SELECT unique2 FROM ten_k WHERE unique2 < 20; -- 20 values, sorted
unique2 SELECT unique2 FROM ten_k WHERE unique2 < 20;
------- unique2
0 ---------
1 0
2 1
3 2
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
19
(20 rows) (20 rows)
QUERY: SELECT hundred FROM ten_k WHERE hundred = 50; -- 100 values, sorted
hundred SELECT hundred FROM ten_k WHERE hundred = 50;
------- hundred
50 ---------
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50 50
50
(100 rows) (100 rows)
QUERY: ALTER TABLE ten_k RENAME TO tenk1; ALTER TABLE ten_k RENAME TO tenk1;
QUERY: SELECT unique1 FROM tenk1 WHERE unique1 < 5; -- 5 values, sorted
unique1 SELECT unique1 FROM tenk1 WHERE unique1 < 5;
------- unique1
0 ---------
1 0
2 1
3 2
4 3
4
(5 rows) (5 rows)
QUERY: SELECT b.* --
-- BTREE_INDEX
-- test retrieval of min/max keys for each index
--
SELECT b.*
FROM bt_i4_heap b FROM bt_i4_heap b
WHERE b.seqno < 1; WHERE b.seqno < 1;
seqno| random seqno | random
-----+---------- -------+------------
0|1935401906 0 | 1935401906
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_i4_heap b FROM bt_i4_heap b
WHERE b.seqno >= 9999; WHERE b.seqno >= 9999;
seqno| random seqno | random
-----+---------- -------+------------
9999|1227676208 9999 | 1227676208
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_i4_heap b FROM bt_i4_heap b
WHERE b.seqno = 4500; WHERE b.seqno = 4500;
seqno| random seqno | random
-----+---------- -------+------------
4500|2080851358 4500 | 2080851358
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_name_heap b FROM bt_name_heap b
WHERE b.seqno < '1'::name; WHERE b.seqno < '1'::name;
seqno| random seqno | random
-----+---------- -------+------------
0|1935401906 0 | 1935401906
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_name_heap b FROM bt_name_heap b
WHERE b.seqno >= '9999'::name; WHERE b.seqno >= '9999'::name;
seqno| random seqno | random
-----+---------- -------+------------
9999|1227676208 9999 | 1227676208
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_name_heap b FROM bt_name_heap b
WHERE b.seqno = '4500'::name; WHERE b.seqno = '4500'::name;
seqno| random seqno | random
-----+---------- -------+------------
4500|2080851358 4500 | 2080851358
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_txt_heap b FROM bt_txt_heap b
WHERE b.seqno < '1'::text; WHERE b.seqno < '1'::text;
seqno| random seqno | random
-----+---------- -------+------------
0|1935401906 0 | 1935401906
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_txt_heap b FROM bt_txt_heap b
WHERE b.seqno >= '9999'::text; WHERE b.seqno >= '9999'::text;
seqno| random seqno | random
-----+---------- -------+------------
9999|1227676208 9999 | 1227676208
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_txt_heap b FROM bt_txt_heap b
WHERE b.seqno = '4500'::text; WHERE b.seqno = '4500'::text;
seqno| random seqno | random
-----+---------- -------+------------
4500|2080851358 4500 | 2080851358
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_f8_heap b FROM bt_f8_heap b
WHERE b.seqno < '1'::float8; WHERE b.seqno < '1'::float8;
seqno| random seqno | random
-----+---------- -------+------------
0|1935401906 0 | 1935401906
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_f8_heap b FROM bt_f8_heap b
WHERE b.seqno >= '9999'::float8; WHERE b.seqno >= '9999'::float8;
seqno| random seqno | random
-----+---------- -------+------------
9999|1227676208 9999 | 1227676208
(1 row) (1 row)
QUERY: SELECT b.* SELECT b.*
FROM bt_f8_heap b FROM bt_f8_heap b
WHERE b.seqno = '4500'::float8; WHERE b.seqno = '4500'::float8;
seqno| random seqno | random
-----+---------- -------+------------
4500|2080851358 4500 | 2080851358
(1 row) (1 row)
QUERY: SELECT hash_i4_heap.* --
-- HASH_INDEX
-- grep 843938989 hash.data
--
SELECT hash_i4_heap.*
WHERE hash_i4_heap.random = 843938989; WHERE hash_i4_heap.random = 843938989;
seqno| random seqno | random
-----+--------- -------+-----------
15|843938989 15 | 843938989
(1 row) (1 row)
QUERY: SELECT hash_i4_heap.* --
-- hash index
-- grep 66766766 hash.data
--
SELECT hash_i4_heap.*
WHERE hash_i4_heap.random = 66766766; WHERE hash_i4_heap.random = 66766766;
seqno|random seqno | random
-----+------ -------+--------
(0 rows) (0 rows)
QUERY: SELECT hash_name_heap.* --
-- hash index
-- grep 1505703298 hash.data
--
SELECT hash_name_heap.*
WHERE hash_name_heap.random = '1505703298'::name; WHERE hash_name_heap.random = '1505703298'::name;
seqno| random seqno | random
-----+---------- -------+------------
9838|1505703298 9838 | 1505703298
(1 row) (1 row)
QUERY: SELECT hash_name_heap.* --
-- hash index
-- grep 7777777 hash.data
--
SELECT hash_name_heap.*
WHERE hash_name_heap.random = '7777777'::name; WHERE hash_name_heap.random = '7777777'::name;
seqno|random seqno | random
-----+------ -------+--------
(0 rows) (0 rows)
QUERY: SELECT hash_txt_heap.* --
-- hash index
-- grep 1351610853 hash.data
--
SELECT hash_txt_heap.*
WHERE hash_txt_heap.random = '1351610853'::text; WHERE hash_txt_heap.random = '1351610853'::text;
seqno| random seqno | random
-----+---------- -------+------------
5677|1351610853 5677 | 1351610853
(1 row) (1 row)
QUERY: SELECT hash_txt_heap.* --
-- hash index
-- grep 111111112222222233333333 hash.data
--
SELECT hash_txt_heap.*
WHERE hash_txt_heap.random = '111111112222222233333333'::text; WHERE hash_txt_heap.random = '111111112222222233333333'::text;
seqno|random seqno | random
-----+------ -------+--------
(0 rows) (0 rows)
QUERY: SELECT hash_f8_heap.* --
-- hash index
-- grep 444705537 hash.data
--
SELECT hash_f8_heap.*
WHERE hash_f8_heap.random = '444705537'::float8; WHERE hash_f8_heap.random = '444705537'::float8;
seqno| random seqno | random
-----+--------- -------+-----------
7853|444705537 7853 | 444705537
(1 row) (1 row)
QUERY: SELECT hash_f8_heap.* --
-- hash index
-- grep 88888888 hash.data
--
SELECT hash_f8_heap.*
WHERE hash_f8_heap.random = '88888888'::float8; WHERE hash_f8_heap.random = '88888888'::float8;
seqno|random seqno | random
-----+------ -------+--------
(0 rows) (0 rows)
QUERY: UPDATE hash_i4_heap --
-- hash index
-- grep '^90[^0-9]' hashovfl.data
--
-- SELECT count(*) AS i988 FROM hash_ovfl_heap
-- WHERE x = 90;
--
-- hash index
-- grep '^1000[^0-9]' hashovfl.data
--
-- SELECT count(*) AS i0 FROM hash_ovfl_heap
-- WHERE x = 1000;
--
-- HASH
--
UPDATE hash_i4_heap
SET random = 1 SET random = 1
WHERE hash_i4_heap.seqno = 1492; WHERE hash_i4_heap.seqno = 1492;
QUERY: SELECT h.seqno AS i1492, h.random AS i1 SELECT h.seqno AS i1492, h.random AS i1
FROM hash_i4_heap h FROM hash_i4_heap h
WHERE h.random = 1; WHERE h.random = 1;
i1492|i1 i1492 | i1
-----+-- -------+----
1492| 1 1492 | 1
(1 row) (1 row)
QUERY: UPDATE hash_i4_heap UPDATE hash_i4_heap
SET seqno = 20000 SET seqno = 20000
WHERE hash_i4_heap.random = 1492795354; WHERE hash_i4_heap.random = 1492795354;
QUERY: SELECT h.seqno AS i20000 SELECT h.seqno AS i20000
FROM hash_i4_heap h FROM hash_i4_heap h
WHERE h.random = 1492795354; WHERE h.random = 1492795354;
i20000 i20000
------ --------
20000 20000
(1 row) (1 row)
QUERY: UPDATE hash_name_heap UPDATE hash_name_heap
SET random = '0123456789abcdef'::name SET random = '0123456789abcdef'::name
WHERE hash_name_heap.seqno = 6543; WHERE hash_name_heap.seqno = 6543;
QUERY: SELECT h.seqno AS i6543, h.random AS c0_to_f SELECT h.seqno AS i6543, h.random AS c0_to_f
FROM hash_name_heap h FROM hash_name_heap h
WHERE h.random = '0123456789abcdef'::name; WHERE h.random = '0123456789abcdef'::name;
i6543|c0_to_f i6543 | c0_to_f
-----+---------------- -------+------------------
6543|0123456789abcdef 6543 | 0123456789abcdef
(1 row) (1 row)
QUERY: UPDATE hash_name_heap UPDATE hash_name_heap
SET seqno = 20000 SET seqno = 20000
WHERE hash_name_heap.random = '76652222'::name; WHERE hash_name_heap.random = '76652222'::name;
QUERY: SELECT h.seqno AS emptyset --
-- this is the row we just replaced; index scan should return zero rows
--
SELECT h.seqno AS emptyset
FROM hash_name_heap h FROM hash_name_heap h
WHERE h.random = '76652222'::name; WHERE h.random = '76652222'::name;
emptyset emptyset
-------- ----------
(0 rows) (0 rows)
QUERY: UPDATE hash_txt_heap UPDATE hash_txt_heap
SET random = '0123456789abcdefghijklmnop'::text SET random = '0123456789abcdefghijklmnop'::text
WHERE hash_txt_heap.seqno = 4002; WHERE hash_txt_heap.seqno = 4002;
QUERY: SELECT h.seqno AS i4002, h.random AS c0_to_p SELECT h.seqno AS i4002, h.random AS c0_to_p
FROM hash_txt_heap h FROM hash_txt_heap h
WHERE h.random = '0123456789abcdefghijklmnop'::text; WHERE h.random = '0123456789abcdefghijklmnop'::text;
i4002|c0_to_p i4002 | c0_to_p
-----+-------------------------- -------+----------------------------
4002|0123456789abcdefghijklmnop 4002 | 0123456789abcdefghijklmnop
(1 row) (1 row)
QUERY: UPDATE hash_txt_heap UPDATE hash_txt_heap
SET seqno = 20000 SET seqno = 20000
WHERE hash_txt_heap.random = '959363399'::text; WHERE hash_txt_heap.random = '959363399'::text;
QUERY: SELECT h.seqno AS t20000 SELECT h.seqno AS t20000
FROM hash_txt_heap h FROM hash_txt_heap h
WHERE h.random = '959363399'::text; WHERE h.random = '959363399'::text;
t20000 t20000
------ --------
20000 20000
(1 row) (1 row)
QUERY: UPDATE hash_f8_heap UPDATE hash_f8_heap
SET random = '-1234.1234'::float8 SET random = '-1234.1234'::float8
WHERE hash_f8_heap.seqno = 8906; WHERE hash_f8_heap.seqno = 8906;
QUERY: SELECT h.seqno AS i8096, h.random AS f1234_1234 SELECT h.seqno AS i8096, h.random AS f1234_1234
FROM hash_f8_heap h FROM hash_f8_heap h
WHERE h.random = '-1234.1234'::float8; WHERE h.random = '-1234.1234'::float8;
i8096|f1234_1234 i8096 | f1234_1234
-----+---------- -------+------------
8906|-1234.1234 8906 | -1234.1234
(1 row) (1 row)
QUERY: UPDATE hash_f8_heap UPDATE hash_f8_heap
SET seqno = 20000 SET seqno = 20000
WHERE hash_f8_heap.random = '488912369'::float8; WHERE hash_f8_heap.random = '488912369'::float8;
QUERY: SELECT h.seqno AS f20000 SELECT h.seqno AS f20000
FROM hash_f8_heap h FROM hash_f8_heap h
WHERE h.random = '488912369'::float8; WHERE h.random = '488912369'::float8;
f20000 f20000
------ --------
20000 20000
(1 row) (1 row)
-- UPDATE hash_ovfl_heap
-- SET x = 1000
-- WHERE x = 90;
-- this vacuums the index as well
-- VACUUM hash_ovfl_heap;
-- SELECT count(*) AS i0 FROM hash_ovfl_heap
-- WHERE x = 90;
-- SELECT count(*) AS i988 FROM hash_ovfl_heap
-- WHERE x = 1000;
QUERY: CREATE TABLE JOIN_TBL ( --
-- JOIN
-- Test join clauses
--
CREATE TABLE JOIN1_TBL (
i integer, i integer,
j integer, j integer,
x text t text
); );
QUERY: CREATE TABLE JOIN2_TBL ( CREATE TABLE JOIN2_TBL (
i integer, i integer,
k integer k integer
); );
QUERY: INSERT INTO JOIN_TBL VALUES (1, 3, 'one'); CREATE TABLE JOIN3_TBL (
QUERY: INSERT INTO JOIN_TBL VALUES (2, 2, 'two'); i integer,
QUERY: INSERT INTO JOIN_TBL VALUES (3, 1, 'three'); j integer,
QUERY: INSERT INTO JOIN_TBL VALUES (4, 0, 'four'); y integer
QUERY: INSERT INTO JOIN2_TBL VALUES (1, -1); );
QUERY: INSERT INTO JOIN2_TBL VALUES (2, 2); CREATE TABLE JOIN4_TBL (
QUERY: INSERT INTO JOIN2_TBL VALUES (3, -3); k integer,
QUERY: INSERT INTO JOIN2_TBL VALUES (2, 4); z integer
QUERY: SELECT '' AS "xxx", * );
FROM JOIN_TBL CROSS JOIN JOIN2_TBL; INSERT INTO JOIN1_TBL VALUES (1, 3, 'one');
xxx|i|j|x |i| k INSERT INTO JOIN1_TBL VALUES (2, 2, 'two');
---+-+-+-----+-+-- INSERT INTO JOIN1_TBL VALUES (3, 1, 'three');
|1|3|one |1|-1 INSERT INTO JOIN1_TBL VALUES (4, 0, 'four');
|2|2|two |1|-1 INSERT INTO JOIN2_TBL VALUES (1, -1);
|3|1|three|1|-1 INSERT INTO JOIN2_TBL VALUES (2, 2);
|4|0|four |1|-1 INSERT INTO JOIN2_TBL VALUES (3, -3);
|1|3|one |2| 2 INSERT INTO JOIN2_TBL VALUES (2, 4);
|2|2|two |2| 2 --
|3|1|three|2| 2 -- CROSS JOIN
|4|0|four |2| 2 -- Qualifications are not allowed on cross joins,
|1|3|one |3|-3 -- which degenerate into a standard unqualified inner join.
|2|2|two |3|-3 --
|3|1|three|3|-3 SELECT '' AS "xxx", *
|4|0|four |3|-3 FROM JOIN1_TBL CROSS JOIN JOIN2_TBL;
|1|3|one |2| 4 xxx | i | j | t | i | k
|2|2|two |2| 4 -----+---+---+-------+---+----
|3|1|three|2| 4 | 1 | 3 | one | 1 | -1
|4|0|four |2| 4 | 2 | 2 | two | 1 | -1
| 3 | 1 | three | 1 | -1
| 4 | 0 | four | 1 | -1
| 1 | 3 | one | 2 | 2
| 2 | 2 | two | 2 | 2
| 3 | 1 | three | 2 | 2
| 4 | 0 | four | 2 | 2
| 1 | 3 | one | 3 | -3
| 2 | 2 | two | 3 | -3
| 3 | 1 | three | 3 | -3
| 4 | 0 | four | 3 | -3
| 1 | 3 | one | 2 | 4
| 2 | 2 | two | 2 | 4
| 3 | 1 | three | 2 | 4
| 4 | 0 | four | 2 | 4
(16 rows) (16 rows)
QUERY: SELECT '' AS "xxx", * SELECT '' AS "xxx", i, k, t
FROM JOIN_TBL NATURAL JOIN JOIN2_TBL; FROM JOIN1_TBL CROSS JOIN JOIN2_TBL;
ERROR: Column 'i' is ambiguous
SELECT '' AS "xxx", ii, tt, kk
FROM JOIN1_TBL CROSS JOIN JOIN2_TBL AS JT (ii, jj, tt, ii2, kk);
ERROR: parser: parse error at or near "("
SELECT '' AS "xxx", jt.ii, jt.jj, jt.kk
FROM JOIN1_TBL CROSS JOIN JOIN2_TBL AS JT (ii, jj, tt, ii2, kk);
ERROR: parser: parse error at or near "("
--
--
-- Inner joins (equi-joins)
--
--
--
-- Inner joins (equi-joins) with USING clause
-- The USING syntax changes the shape of the resulting table
-- by including a column in the USING clause only once in the result.
--
-- Inner equi-join on all columns with the same name
SELECT '' AS "xxx", *
FROM JOIN1_TBL NATURAL JOIN JOIN2_TBL;
ERROR: JOIN expressions are not yet implemented
-- Inner equi-join on specified column
SELECT '' AS "xxx", *
FROM JOIN1_TBL INNER JOIN JOIN2_TBL USING (i);
ERROR: JOIN expressions are not yet implemented ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", * -- Same as above, slightly different syntax
FROM JOIN_TBL INNER JOIN JOIN2_TBL USING (i); SELECT '' AS "xxx", *
FROM JOIN1_TBL JOIN JOIN2_TBL USING (i);
ERROR: JOIN expressions are not yet implemented ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", * --
FROM JOIN_TBL JOIN JOIN2_TBL ON (JOIN_TBL.i = JOIN2_TBL.i); -- Inner joins (equi-joins)
--
SELECT '' AS "xxx", *
FROM JOIN1_TBL JOIN JOIN2_TBL ON (JOIN1_TBL.i = JOIN2_TBL.i);
ERROR: JOIN expressions are not yet implemented ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", * SELECT '' AS "xxx", *
FROM JOIN_TBL JOIN JOIN2_TBL ON (JOIN_TBL.i = JOIN2_TBL.k); FROM JOIN1_TBL JOIN JOIN2_TBL ON (JOIN1_TBL.i = JOIN2_TBL.k);
ERROR: JOIN expressions are not yet implemented ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", * SELECT '' AS "xxx", *
FROM JOIN_TBL CROSS JOIN JOIN2_TBL; FROM JOIN1_TBL CROSS JOIN JOIN2_TBL;
xxx|i|j|x |i| k xxx | i | j | t | i | k
---+-+-+-----+-+-- -----+---+---+-------+---+----
|1|3|one |1|-1 | 1 | 3 | one | 1 | -1
|2|2|two |1|-1 | 2 | 2 | two | 1 | -1
|3|1|three|1|-1 | 3 | 1 | three | 1 | -1
|4|0|four |1|-1 | 4 | 0 | four | 1 | -1
|1|3|one |2| 2 | 1 | 3 | one | 2 | 2
|2|2|two |2| 2 | 2 | 2 | two | 2 | 2
|3|1|three|2| 2 | 3 | 1 | three | 2 | 2
|4|0|four |2| 2 | 4 | 0 | four | 2 | 2
|1|3|one |3|-3 | 1 | 3 | one | 3 | -3
|2|2|two |3|-3 | 2 | 2 | two | 3 | -3
|3|1|three|3|-3 | 3 | 1 | three | 3 | -3
|4|0|four |3|-3 | 4 | 0 | four | 3 | -3
|1|3|one |2| 4 | 1 | 3 | one | 2 | 4
|2|2|two |2| 4 | 2 | 2 | two | 2 | 4
|3|1|three|2| 4 | 3 | 1 | three | 2 | 4
|4|0|four |2| 4 | 4 | 0 | four | 2 | 4
(16 rows) (16 rows)
QUERY: SELECT '' AS "xxx", * --
FROM JOIN_TBL JOIN JOIN2_TBL ON (JOIN_TBL.i <= JOIN2_TBL.k); -- Non-equi-joins
--
SELECT '' AS "xxx", *
FROM JOIN1_TBL JOIN JOIN2_TBL ON (JOIN1_TBL.i <= JOIN2_TBL.k);
ERROR: JOIN expressions are not yet implemented ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", * --
FROM JOIN_TBL OUTER JOIN JOIN2_TBL USING (i); -- Outer joins
--
SELECT '' AS "xxx", *
NOTICE: OUTER JOIN not yet implemented NOTICE: OUTER JOIN not yet implemented
FROM JOIN1_TBL OUTER JOIN JOIN2_TBL USING (i);
ERROR: JOIN expressions are not yet implemented ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", * SELECT '' AS "xxx", *
FROM JOIN_TBL LEFT OUTER JOIN JOIN2_TBL USING (i);
NOTICE: LEFT OUTER JOIN not yet implemented NOTICE: LEFT OUTER JOIN not yet implemented
FROM JOIN1_TBL LEFT OUTER JOIN JOIN2_TBL USING (i);
ERROR: JOIN expressions are not yet implemented ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", * SELECT '' AS "xxx", *
FROM JOIN_TBL RIGHT OUTER JOIN JOIN2_TBL USING (i);
NOTICE: RIGHT OUTER JOIN not yet implemented NOTICE: RIGHT OUTER JOIN not yet implemented
FROM JOIN1_TBL RIGHT OUTER JOIN JOIN2_TBL USING (i);
ERROR: JOIN expressions are not yet implemented ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", * SELECT '' AS "xxx", *
FROM JOIN_TBL FULL OUTER JOIN JOIN2_TBL USING (i);
NOTICE: FULL OUTER JOIN not yet implemented NOTICE: FULL OUTER JOIN not yet implemented
FROM JOIN1_TBL FULL OUTER JOIN JOIN2_TBL USING (i);
ERROR: JOIN expressions are not yet implemented ERROR: JOIN expressions are not yet implemented
QUERY: DROP TABLE JOIN_TBL; --
QUERY: DROP TABLE JOIN2_TBL; -- More complicated constructs
--
--
-- Clean up
--
DROP TABLE JOIN1_TBL;
DROP TABLE JOIN2_TBL;
QUERY: SELECT ''::text AS two, unique1, unique2, stringu1 --
FROM onek WHERE unique1 > 50 -- LIMIT
-- Check the LIMIT/OFFSET feature of SELECT
--
SELECT ''::text AS two, unique1, unique2, stringu1
FROM onek WHERE unique1 > 50
ORDER BY unique1 LIMIT 2; ORDER BY unique1 LIMIT 2;
two|unique1|unique2|stringu1 two | unique1 | unique2 | stringu1
---+-------+-------+-------- -----+---------+---------+----------
| 51| 76|ZBAAAA | 51 | 76 | ZBAAAA
| 52| 985|ACAAAA | 52 | 985 | ACAAAA
(2 rows) (2 rows)
QUERY: SELECT ''::text AS five, unique1, unique2, stringu1 SELECT ''::text AS five, unique1, unique2, stringu1
FROM onek WHERE unique1 > 60 FROM onek WHERE unique1 > 60
ORDER BY unique1 LIMIT 5; ORDER BY unique1 LIMIT 5;
five|unique1|unique2|stringu1 five | unique1 | unique2 | stringu1
----+-------+-------+-------- ------+---------+---------+----------
| 61| 560|JCAAAA | 61 | 560 | JCAAAA
| 62| 633|KCAAAA | 62 | 633 | KCAAAA
| 63| 296|LCAAAA | 63 | 296 | LCAAAA
| 64| 479|MCAAAA | 64 | 479 | MCAAAA
| 65| 64|NCAAAA | 65 | 64 | NCAAAA
(5 rows) (5 rows)
QUERY: SELECT ''::text AS two, unique1, unique2, stringu1 SELECT ''::text AS two, unique1, unique2, stringu1
FROM onek WHERE unique1 > 60 AND unique1 < 63 FROM onek WHERE unique1 > 60 AND unique1 < 63
ORDER BY unique1 LIMIT 5; ORDER BY unique1 LIMIT 5;
two|unique1|unique2|stringu1 two | unique1 | unique2 | stringu1
---+-------+-------+-------- -----+---------+---------+----------
| 61| 560|JCAAAA | 61 | 560 | JCAAAA
| 62| 633|KCAAAA | 62 | 633 | KCAAAA
(2 rows) (2 rows)
QUERY: SELECT ''::text AS three, unique1, unique2, stringu1 SELECT ''::text AS three, unique1, unique2, stringu1
FROM onek WHERE unique1 > 100 FROM onek WHERE unique1 > 100
ORDER BY unique1 LIMIT 3 OFFSET 20; ORDER BY unique1 LIMIT 3 OFFSET 20;
three|unique1|unique2|stringu1 three | unique1 | unique2 | stringu1
-----+-------+-------+-------- -------+---------+---------+----------
| 121| 700|REAAAA | 121 | 700 | REAAAA
| 122| 519|SEAAAA | 122 | 519 | SEAAAA
| 123| 777|TEAAAA | 123 | 777 | TEAAAA
(3 rows) (3 rows)
QUERY: SELECT ''::text AS zero, unique1, unique2, stringu1 SELECT ''::text AS zero, unique1, unique2, stringu1
FROM onek WHERE unique1 < 50 FROM onek WHERE unique1 < 50
ORDER BY unique1 DESC LIMIT 8 OFFSET 99; ORDER BY unique1 DESC LIMIT 8 OFFSET 99;
zero|unique1|unique2|stringu1 zero | unique1 | unique2 | stringu1
----+-------+-------+-------- ------+---------+---------+----------
(0 rows) (0 rows)
QUERY: SELECT ''::text AS eleven, unique1, unique2, stringu1 SELECT ''::text AS eleven, unique1, unique2, stringu1
FROM onek WHERE unique1 < 50 FROM onek WHERE unique1 < 50
ORDER BY unique1 DESC LIMIT 20 OFFSET 39; ORDER BY unique1 DESC LIMIT 20 OFFSET 39;
eleven|unique1|unique2|stringu1 eleven | unique1 | unique2 | stringu1
------+-------+-------+-------- --------+---------+---------+----------
| 10| 520|KAAAAA | 10 | 520 | KAAAAA
| 9| 49|JAAAAA | 9 | 49 | JAAAAA
| 8| 653|IAAAAA | 8 | 653 | IAAAAA
| 7| 647|HAAAAA | 7 | 647 | HAAAAA
| 6| 978|GAAAAA | 6 | 978 | GAAAAA
| 5| 541|FAAAAA | 5 | 541 | FAAAAA
| 4| 833|EAAAAA | 4 | 833 | EAAAAA
| 3| 431|DAAAAA | 3 | 431 | DAAAAA
| 2| 326|CAAAAA | 2 | 326 | CAAAAA
| 1| 214|BAAAAA | 1 | 214 | BAAAAA
| 0| 998|AAAAAA | 0 | 998 | AAAAAA
(11 rows) (11 rows)
QUERY: SELECT ''::text AS ten, unique1, unique2, stringu1 SELECT ''::text AS ten, unique1, unique2, stringu1
FROM onek FROM onek
ORDER BY unique1 OFFSET 990; ORDER BY unique1 OFFSET 990;
ten|unique1|unique2|stringu1 ten | unique1 | unique2 | stringu1
---+-------+-------+-------- -----+---------+---------+----------
| 990| 369|CMAAAA | 990 | 369 | CMAAAA
| 991| 426|DMAAAA | 991 | 426 | DMAAAA
| 992| 363|EMAAAA | 992 | 363 | EMAAAA
| 993| 661|FMAAAA | 993 | 661 | FMAAAA
| 994| 695|GMAAAA | 994 | 695 | GMAAAA
| 995| 144|HMAAAA | 995 | 144 | HMAAAA
| 996| 258|IMAAAA | 996 | 258 | IMAAAA
| 997| 21|JMAAAA | 997 | 21 | JMAAAA
| 998| 549|KMAAAA | 998 | 549 | KMAAAA
| 999| 152|LMAAAA | 999 | 152 | LMAAAA
(10 rows) (10 rows)
QUERY: SELECT ''::text AS five, unique1, unique2, stringu1 SELECT ''::text AS five, unique1, unique2, stringu1
FROM onek FROM onek
ORDER BY unique1 OFFSET 990 LIMIT 5; ORDER BY unique1 OFFSET 990 LIMIT 5;
five|unique1|unique2|stringu1 five | unique1 | unique2 | stringu1
----+-------+-------+-------- ------+---------+---------+----------
| 990| 369|CMAAAA | 990 | 369 | CMAAAA
| 991| 426|DMAAAA | 991 | 426 | DMAAAA
| 992| 363|EMAAAA | 992 | 363 | EMAAAA
| 993| 661|FMAAAA | 993 | 661 | FMAAAA
| 994| 695|GMAAAA | 994 | 695 | GMAAAA
(5 rows) (5 rows)
QUERY: SELECT ''::text AS five, unique1, unique2, stringu1 SELECT ''::text AS five, unique1, unique2, stringu1
FROM onek FROM onek
ORDER BY unique1 LIMIT 5, 900; ORDER BY unique1 LIMIT 5, 900;
five|unique1|unique2|stringu1 five | unique1 | unique2 | stringu1
----+-------+-------+-------- ------+---------+---------+----------
| 900| 913|QIAAAA | 900 | 913 | QIAAAA
| 901| 931|RIAAAA | 901 | 931 | RIAAAA
| 902| 702|SIAAAA | 902 | 702 | SIAAAA
| 903| 641|TIAAAA | 903 | 641 | TIAAAA
| 904| 793|UIAAAA | 904 | 793 | UIAAAA
(5 rows) (5 rows)
QUERY: create table Room ( --
-- PLPGSQL
--
create table Room (
roomno char(8), roomno char(8),
comment text comment text
); );
QUERY: create unique index Room_rno on Room using btree (roomno bpchar_ops); create unique index Room_rno on Room using btree (roomno bpchar_ops);
QUERY: create table WSlot ( create table WSlot (
slotname char(20), slotname char(20),
roomno char(8), roomno char(8),
slotlink char(20), slotlink char(20),
backlink char(20) backlink char(20)
); );
QUERY: create unique index WSlot_name on WSlot using btree (slotname bpchar_ops); create unique index WSlot_name on WSlot using btree (slotname bpchar_ops);
QUERY: create table PField ( create table PField (
name text, name text,
comment text comment text
); );
QUERY: create unique index PField_name on PField using btree (name text_ops); create unique index PField_name on PField using btree (name text_ops);
QUERY: create table PSlot ( create table PSlot (
slotname char(20), slotname char(20),
pfname text, pfname text,
slotlink char(20), slotlink char(20),
backlink char(20) backlink char(20)
); );
QUERY: create unique index PSlot_name on PSlot using btree (slotname bpchar_ops); create unique index PSlot_name on PSlot using btree (slotname bpchar_ops);
QUERY: create table PLine ( create table PLine (
slotname char(20), slotname char(20),
phonenumber char(20), phonenumber char(20),
comment text, comment text,
backlink char(20) backlink char(20)
); );
QUERY: create unique index PLine_name on PLine using btree (slotname bpchar_ops); create unique index PLine_name on PLine using btree (slotname bpchar_ops);
QUERY: create table Hub ( create table Hub (
name char(14), name char(14),
comment text, comment text,
nslots integer nslots integer
); );
QUERY: create unique index Hub_name on Hub using btree (name bpchar_ops); create unique index Hub_name on Hub using btree (name bpchar_ops);
QUERY: create table HSlot ( create table HSlot (
slotname char(20), slotname char(20),
hubname char(14), hubname char(14),
slotno integer, slotno integer,
slotlink char(20) slotlink char(20)
); );
QUERY: create unique index HSlot_name on HSlot using btree (slotname bpchar_ops); create unique index HSlot_name on HSlot using btree (slotname bpchar_ops);
QUERY: create index HSlot_hubname on HSlot using btree (hubname bpchar_ops); create index HSlot_hubname on HSlot using btree (hubname bpchar_ops);
QUERY: create table System ( create table System (
name text, name text,
comment text comment text
); );
QUERY: create unique index System_name on System using btree (name text_ops); create unique index System_name on System using btree (name text_ops);
QUERY: create table IFace ( create table IFace (
slotname char(20), slotname char(20),
sysname text, sysname text,
ifname text, ifname text,
slotlink char(20) slotlink char(20)
); );
QUERY: create unique index IFace_name on IFace using btree (slotname bpchar_ops); create unique index IFace_name on IFace using btree (slotname bpchar_ops);
QUERY: create table PHone ( create table PHone (
slotname char(20), slotname char(20),
comment text, comment text,
slotlink char(20) slotlink char(20)
); );
QUERY: create unique index PHone_name on PHone using btree (slotname bpchar_ops); create unique index PHone_name on PHone using btree (slotname bpchar_ops);
QUERY: create function tg_room_au() returns opaque as ' -- ************************************************************
-- *
-- * Trigger procedures and functions for the patchfield
-- * test of PL/pgSQL
-- *
-- * $Header: /cvsroot/pgsql/src/test/regress/expected/plpgsql.out,v 1.3 2000/01/09 03:48:37 tgl Exp $
-- *
-- ************************************************************
-- ************************************************************
-- * AFTER UPDATE on Room
-- * - If room no changes let wall slots follow
-- ************************************************************
create function tg_room_au() returns opaque as '
begin begin
if new.roomno != old.roomno then if new.roomno != old.roomno then
update WSlot set roomno = new.roomno where roomno = old.roomno; update WSlot set roomno = new.roomno where roomno = old.roomno;
...@@ -69,17 +84,25 @@ begin ...@@ -69,17 +84,25 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_room_au after update create trigger tg_room_au after update
on Room for each row execute procedure tg_room_au(); on Room for each row execute procedure tg_room_au();
QUERY: create function tg_room_ad() returns opaque as ' -- ************************************************************
-- * AFTER DELETE on Room
-- * - delete wall slots in this room
-- ************************************************************
create function tg_room_ad() returns opaque as '
begin begin
delete from WSlot where roomno = old.roomno; delete from WSlot where roomno = old.roomno;
return old; return old;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_room_ad after delete create trigger tg_room_ad after delete
on Room for each row execute procedure tg_room_ad(); on Room for each row execute procedure tg_room_ad();
QUERY: create function tg_wslot_biu() returns opaque as ' -- ************************************************************
-- * BEFORE INSERT or UPDATE on WSlot
-- * - Check that room exists
-- ************************************************************
create function tg_wslot_biu() returns opaque as '
begin begin
if count(*) = 0 from Room where roomno = new.roomno then if count(*) = 0 from Room where roomno = new.roomno then
raise exception ''Room % does not exist'', new.roomno; raise exception ''Room % does not exist'', new.roomno;
...@@ -87,9 +110,13 @@ begin ...@@ -87,9 +110,13 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_wslot_biu before insert or update create trigger tg_wslot_biu before insert or update
on WSlot for each row execute procedure tg_wslot_biu(); on WSlot for each row execute procedure tg_wslot_biu();
QUERY: create function tg_pfield_au() returns opaque as ' -- ************************************************************
-- * AFTER UPDATE on PField
-- * - Let PSlots of this field follow
-- ************************************************************
create function tg_pfield_au() returns opaque as '
begin begin
if new.name != old.name then if new.name != old.name then
update PSlot set pfname = new.name where pfname = old.name; update PSlot set pfname = new.name where pfname = old.name;
...@@ -97,17 +124,25 @@ begin ...@@ -97,17 +124,25 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_pfield_au after update create trigger tg_pfield_au after update
on PField for each row execute procedure tg_pfield_au(); on PField for each row execute procedure tg_pfield_au();
QUERY: create function tg_pfield_ad() returns opaque as ' -- ************************************************************
-- * AFTER DELETE on PField
-- * - Remove all slots of this patchfield
-- ************************************************************
create function tg_pfield_ad() returns opaque as '
begin begin
delete from PSlot where pfname = old.name; delete from PSlot where pfname = old.name;
return old; return old;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_pfield_ad after delete create trigger tg_pfield_ad after delete
on PField for each row execute procedure tg_pfield_ad(); on PField for each row execute procedure tg_pfield_ad();
QUERY: create function tg_pslot_biu() returns opaque as ' -- ************************************************************
-- * BEFORE INSERT or UPDATE on PSlot
-- * - Ensure that our patchfield does exist
-- ************************************************************
create function tg_pslot_biu() returns opaque as '
declare declare
pfrec record; pfrec record;
rename new to ps; rename new to ps;
...@@ -119,9 +154,13 @@ begin ...@@ -119,9 +154,13 @@ begin
return ps; return ps;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_pslot_biu before insert or update create trigger tg_pslot_biu before insert or update
on PSlot for each row execute procedure tg_pslot_biu(); on PSlot for each row execute procedure tg_pslot_biu();
QUERY: create function tg_system_au() returns opaque as ' -- ************************************************************
-- * AFTER UPDATE on System
-- * - If system name changes let interfaces follow
-- ************************************************************
create function tg_system_au() returns opaque as '
begin begin
if new.name != old.name then if new.name != old.name then
update IFace set sysname = new.name where sysname = old.name; update IFace set sysname = new.name where sysname = old.name;
...@@ -129,9 +168,13 @@ begin ...@@ -129,9 +168,13 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_system_au after update create trigger tg_system_au after update
on System for each row execute procedure tg_system_au(); on System for each row execute procedure tg_system_au();
QUERY: create function tg_iface_biu() returns opaque as ' -- ************************************************************
-- * BEFORE INSERT or UPDATE on IFace
-- * - set the slotname to IF.sysname.ifname
-- ************************************************************
create function tg_iface_biu() returns opaque as '
declare declare
sname text; sname text;
sysrec record; sysrec record;
...@@ -150,9 +193,13 @@ begin ...@@ -150,9 +193,13 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_iface_biu before insert or update create trigger tg_iface_biu before insert or update
on IFace for each row execute procedure tg_iface_biu(); on IFace for each row execute procedure tg_iface_biu();
QUERY: create function tg_hub_a() returns opaque as ' -- ************************************************************
-- * AFTER INSERT or UPDATE or DELETE on Hub
-- * - insert/delete/rename slots as required
-- ************************************************************
create function tg_hub_a() returns opaque as '
declare declare
hname text; hname text;
dummy integer; dummy integer;
...@@ -174,9 +221,12 @@ begin ...@@ -174,9 +221,12 @@ begin
end if; end if;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_hub_a after insert or update or delete create trigger tg_hub_a after insert or update or delete
on Hub for each row execute procedure tg_hub_a(); on Hub for each row execute procedure tg_hub_a();
QUERY: create function tg_hub_adjustslots(bpchar, integer, integer) -- ************************************************************
-- * Support function to add/remove slots of Hub
-- ************************************************************
create function tg_hub_adjustslots(bpchar, integer, integer)
returns integer as ' returns integer as '
declare declare
hname alias for $1; hname alias for $1;
...@@ -197,7 +247,12 @@ begin ...@@ -197,7 +247,12 @@ begin
return 0; return 0;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create function tg_hslot_biu() returns opaque as ' -- ************************************************************
-- * BEFORE INSERT or UPDATE on HSlot
-- * - prevent from manual manipulation
-- * - set the slotname to HS.hubname.slotno
-- ************************************************************
create function tg_hslot_biu() returns opaque as '
declare declare
sname text; sname text;
xname HSlot.slotname%TYPE; xname HSlot.slotname%TYPE;
...@@ -227,9 +282,13 @@ begin ...@@ -227,9 +282,13 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_hslot_biu before insert or update create trigger tg_hslot_biu before insert or update
on HSlot for each row execute procedure tg_hslot_biu(); on HSlot for each row execute procedure tg_hslot_biu();
QUERY: create function tg_hslot_bd() returns opaque as ' -- ************************************************************
-- * BEFORE DELETE on HSlot
-- * - prevent from manual manipulation
-- ************************************************************
create function tg_hslot_bd() returns opaque as '
declare declare
hubrec record; hubrec record;
begin begin
...@@ -243,9 +302,13 @@ begin ...@@ -243,9 +302,13 @@ begin
raise exception ''no manual manipulation of HSlot''; raise exception ''no manual manipulation of HSlot'';
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_hslot_bd before delete create trigger tg_hslot_bd before delete
on HSlot for each row execute procedure tg_hslot_bd(); on HSlot for each row execute procedure tg_hslot_bd();
QUERY: create function tg_chkslotname() returns opaque as ' -- ************************************************************
-- * BEFORE INSERT on all slots
-- * - Check name prefix
-- ************************************************************
create function tg_chkslotname() returns opaque as '
begin begin
if substr(new.slotname, 1, 2) != tg_argv[0] then if substr(new.slotname, 1, 2) != tg_argv[0] then
raise exception ''slotname must begin with %'', tg_argv[0]; raise exception ''slotname must begin with %'', tg_argv[0];
...@@ -253,17 +316,21 @@ begin ...@@ -253,17 +316,21 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_chkslotname before insert create trigger tg_chkslotname before insert
on PSlot for each row execute procedure tg_chkslotname('PS'); on PSlot for each row execute procedure tg_chkslotname('PS');
QUERY: create trigger tg_chkslotname before insert create trigger tg_chkslotname before insert
on WSlot for each row execute procedure tg_chkslotname('WS'); on WSlot for each row execute procedure tg_chkslotname('WS');
QUERY: create trigger tg_chkslotname before insert create trigger tg_chkslotname before insert
on PLine for each row execute procedure tg_chkslotname('PL'); on PLine for each row execute procedure tg_chkslotname('PL');
QUERY: create trigger tg_chkslotname before insert create trigger tg_chkslotname before insert
on IFace for each row execute procedure tg_chkslotname('IF'); on IFace for each row execute procedure tg_chkslotname('IF');
QUERY: create trigger tg_chkslotname before insert create trigger tg_chkslotname before insert
on PHone for each row execute procedure tg_chkslotname('PH'); on PHone for each row execute procedure tg_chkslotname('PH');
QUERY: create function tg_chkslotlink() returns opaque as ' -- ************************************************************
-- * BEFORE INSERT or UPDATE on all slots with slotlink
-- * - Set slotlink to empty string if NULL value given
-- ************************************************************
create function tg_chkslotlink() returns opaque as '
begin begin
if new.slotlink isnull then if new.slotlink isnull then
new.slotlink := ''''; new.slotlink := '''';
...@@ -271,17 +338,21 @@ begin ...@@ -271,17 +338,21 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_chkslotlink before insert or update create trigger tg_chkslotlink before insert or update
on PSlot for each row execute procedure tg_chkslotlink(); on PSlot for each row execute procedure tg_chkslotlink();
QUERY: create trigger tg_chkslotlink before insert or update create trigger tg_chkslotlink before insert or update
on WSlot for each row execute procedure tg_chkslotlink(); on WSlot for each row execute procedure tg_chkslotlink();
QUERY: create trigger tg_chkslotlink before insert or update create trigger tg_chkslotlink before insert or update
on IFace for each row execute procedure tg_chkslotlink(); on IFace for each row execute procedure tg_chkslotlink();
QUERY: create trigger tg_chkslotlink before insert or update create trigger tg_chkslotlink before insert or update
on HSlot for each row execute procedure tg_chkslotlink(); on HSlot for each row execute procedure tg_chkslotlink();
QUERY: create trigger tg_chkslotlink before insert or update create trigger tg_chkslotlink before insert or update
on PHone for each row execute procedure tg_chkslotlink(); on PHone for each row execute procedure tg_chkslotlink();
QUERY: create function tg_chkbacklink() returns opaque as ' -- ************************************************************
-- * BEFORE INSERT or UPDATE on all slots with backlink
-- * - Set backlink to empty string if NULL value given
-- ************************************************************
create function tg_chkbacklink() returns opaque as '
begin begin
if new.backlink isnull then if new.backlink isnull then
new.backlink := ''''; new.backlink := '''';
...@@ -289,13 +360,17 @@ begin ...@@ -289,13 +360,17 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_chkbacklink before insert or update create trigger tg_chkbacklink before insert or update
on PSlot for each row execute procedure tg_chkbacklink(); on PSlot for each row execute procedure tg_chkbacklink();
QUERY: create trigger tg_chkbacklink before insert or update create trigger tg_chkbacklink before insert or update
on WSlot for each row execute procedure tg_chkbacklink(); on WSlot for each row execute procedure tg_chkbacklink();
QUERY: create trigger tg_chkbacklink before insert or update create trigger tg_chkbacklink before insert or update
on PLine for each row execute procedure tg_chkbacklink(); on PLine for each row execute procedure tg_chkbacklink();
QUERY: create function tg_pslot_bu() returns opaque as ' -- ************************************************************
-- * BEFORE UPDATE on PSlot
-- * - do delete/insert instead of update if name changes
-- ************************************************************
create function tg_pslot_bu() returns opaque as '
begin begin
if new.slotname != old.slotname then if new.slotname != old.slotname then
delete from PSlot where slotname = old.slotname; delete from PSlot where slotname = old.slotname;
...@@ -315,9 +390,13 @@ begin ...@@ -315,9 +390,13 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_pslot_bu before update create trigger tg_pslot_bu before update
on PSlot for each row execute procedure tg_pslot_bu(); on PSlot for each row execute procedure tg_pslot_bu();
QUERY: create function tg_wslot_bu() returns opaque as ' -- ************************************************************
-- * BEFORE UPDATE on WSlot
-- * - do delete/insert instead of update if name changes
-- ************************************************************
create function tg_wslot_bu() returns opaque as '
begin begin
if new.slotname != old.slotname then if new.slotname != old.slotname then
delete from WSlot where slotname = old.slotname; delete from WSlot where slotname = old.slotname;
...@@ -337,9 +416,13 @@ begin ...@@ -337,9 +416,13 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_wslot_bu before update create trigger tg_wslot_bu before update
on WSlot for each row execute procedure tg_Wslot_bu(); on WSlot for each row execute procedure tg_Wslot_bu();
QUERY: create function tg_pline_bu() returns opaque as ' -- ************************************************************
-- * BEFORE UPDATE on PLine
-- * - do delete/insert instead of update if name changes
-- ************************************************************
create function tg_pline_bu() returns opaque as '
begin begin
if new.slotname != old.slotname then if new.slotname != old.slotname then
delete from PLine where slotname = old.slotname; delete from PLine where slotname = old.slotname;
...@@ -359,9 +442,13 @@ begin ...@@ -359,9 +442,13 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_pline_bu before update create trigger tg_pline_bu before update
on PLine for each row execute procedure tg_pline_bu(); on PLine for each row execute procedure tg_pline_bu();
QUERY: create function tg_iface_bu() returns opaque as ' -- ************************************************************
-- * BEFORE UPDATE on IFace
-- * - do delete/insert instead of update if name changes
-- ************************************************************
create function tg_iface_bu() returns opaque as '
begin begin
if new.slotname != old.slotname then if new.slotname != old.slotname then
delete from IFace where slotname = old.slotname; delete from IFace where slotname = old.slotname;
...@@ -381,9 +468,13 @@ begin ...@@ -381,9 +468,13 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_iface_bu before update create trigger tg_iface_bu before update
on IFace for each row execute procedure tg_iface_bu(); on IFace for each row execute procedure tg_iface_bu();
QUERY: create function tg_hslot_bu() returns opaque as ' -- ************************************************************
-- * BEFORE UPDATE on HSlot
-- * - do delete/insert instead of update if name changes
-- ************************************************************
create function tg_hslot_bu() returns opaque as '
begin begin
if new.slotname != old.slotname or new.hubname != old.hubname then if new.slotname != old.slotname or new.hubname != old.hubname then
delete from HSlot where slotname = old.slotname; delete from HSlot where slotname = old.slotname;
...@@ -403,9 +494,13 @@ begin ...@@ -403,9 +494,13 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_hslot_bu before update create trigger tg_hslot_bu before update
on HSlot for each row execute procedure tg_hslot_bu(); on HSlot for each row execute procedure tg_hslot_bu();
QUERY: create function tg_phone_bu() returns opaque as ' -- ************************************************************
-- * BEFORE UPDATE on PHone
-- * - do delete/insert instead of update if name changes
-- ************************************************************
create function tg_phone_bu() returns opaque as '
begin begin
if new.slotname != old.slotname then if new.slotname != old.slotname then
delete from PHone where slotname = old.slotname; delete from PHone where slotname = old.slotname;
...@@ -423,9 +518,13 @@ begin ...@@ -423,9 +518,13 @@ begin
return new; return new;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_phone_bu before update create trigger tg_phone_bu before update
on PHone for each row execute procedure tg_phone_bu(); on PHone for each row execute procedure tg_phone_bu();
QUERY: create function tg_backlink_a() returns opaque as ' -- ************************************************************
-- * AFTER INSERT or UPDATE or DELETE on slot with backlink
-- * - Ensure that the opponent correctly points back to us
-- ************************************************************
create function tg_backlink_a() returns opaque as '
declare declare
dummy integer; dummy integer;
begin begin
...@@ -458,13 +557,17 @@ begin ...@@ -458,13 +557,17 @@ begin
end if; end if;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_backlink_a after insert or update or delete create trigger tg_backlink_a after insert or update or delete
on PSlot for each row execute procedure tg_backlink_a('PS'); on PSlot for each row execute procedure tg_backlink_a('PS');
QUERY: create trigger tg_backlink_a after insert or update or delete create trigger tg_backlink_a after insert or update or delete
on WSlot for each row execute procedure tg_backlink_a('WS'); on WSlot for each row execute procedure tg_backlink_a('WS');
QUERY: create trigger tg_backlink_a after insert or update or delete create trigger tg_backlink_a after insert or update or delete
on PLine for each row execute procedure tg_backlink_a('PL'); on PLine for each row execute procedure tg_backlink_a('PL');
QUERY: create function tg_backlink_set(bpchar, bpchar) -- ************************************************************
-- * Support function to set the opponents backlink field
-- * if it does not already point to the requested slot
-- ************************************************************
create function tg_backlink_set(bpchar, bpchar)
returns integer as ' returns integer as '
declare declare
myname alias for $1; myname alias for $1;
...@@ -476,11 +579,11 @@ begin ...@@ -476,11 +579,11 @@ begin
mytype := substr(myname, 1, 2); mytype := substr(myname, 1, 2);
link := mytype || substr(blname, 1, 2); link := mytype || substr(blname, 1, 2);
if link = ''PLPL'' then if link = ''PLPL'' then
raise exception raise exception
''backlink between two phone lines does not make sense''; ''backlink between two phone lines does not make sense'';
end if; end if;
if link in (''PLWS'', ''WSPL'') then if link in (''PLWS'', ''WSPL'') then
raise exception raise exception
''direct link of phone line to wall slot not permitted''; ''direct link of phone line to wall slot not permitted'';
end if; end if;
if mytype = ''PS'' then if mytype = ''PS'' then
...@@ -516,7 +619,11 @@ begin ...@@ -516,7 +619,11 @@ begin
raise exception ''illegal backlink beginning with %'', mytype; raise exception ''illegal backlink beginning with %'', mytype;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create function tg_backlink_unset(bpchar, bpchar) -- ************************************************************
-- * Support function to clear out the backlink field if
-- * it still points to specific slot
-- ************************************************************
create function tg_backlink_unset(bpchar, bpchar)
returns integer as ' returns integer as '
declare declare
myname alias for $1; myname alias for $1;
...@@ -557,7 +664,11 @@ begin ...@@ -557,7 +664,11 @@ begin
end if; end if;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create function tg_slotlink_a() returns opaque as ' -- ************************************************************
-- * AFTER INSERT or UPDATE or DELETE on slot with slotlink
-- * - Ensure that the opponent correctly points back to us
-- ************************************************************
create function tg_slotlink_a() returns opaque as '
declare declare
dummy integer; dummy integer;
begin begin
...@@ -590,17 +701,21 @@ begin ...@@ -590,17 +701,21 @@ begin
end if; end if;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create trigger tg_slotlink_a after insert or update or delete create trigger tg_slotlink_a after insert or update or delete
on PSlot for each row execute procedure tg_slotlink_a('PS'); on PSlot for each row execute procedure tg_slotlink_a('PS');
QUERY: create trigger tg_slotlink_a after insert or update or delete create trigger tg_slotlink_a after insert or update or delete
on WSlot for each row execute procedure tg_slotlink_a('WS'); on WSlot for each row execute procedure tg_slotlink_a('WS');
QUERY: create trigger tg_slotlink_a after insert or update or delete create trigger tg_slotlink_a after insert or update or delete
on IFace for each row execute procedure tg_slotlink_a('IF'); on IFace for each row execute procedure tg_slotlink_a('IF');
QUERY: create trigger tg_slotlink_a after insert or update or delete create trigger tg_slotlink_a after insert or update or delete
on HSlot for each row execute procedure tg_slotlink_a('HS'); on HSlot for each row execute procedure tg_slotlink_a('HS');
QUERY: create trigger tg_slotlink_a after insert or update or delete create trigger tg_slotlink_a after insert or update or delete
on PHone for each row execute procedure tg_slotlink_a('PH'); on PHone for each row execute procedure tg_slotlink_a('PH');
QUERY: create function tg_slotlink_set(bpchar, bpchar) -- ************************************************************
-- * Support function to set the opponents slotlink field
-- * if it does not already point to the requested slot
-- ************************************************************
create function tg_slotlink_set(bpchar, bpchar)
returns integer as ' returns integer as '
declare declare
myname alias for $1; myname alias for $1;
...@@ -612,19 +727,19 @@ begin ...@@ -612,19 +727,19 @@ begin
mytype := substr(myname, 1, 2); mytype := substr(myname, 1, 2);
link := mytype || substr(blname, 1, 2); link := mytype || substr(blname, 1, 2);
if link = ''PHPH'' then if link = ''PHPH'' then
raise exception raise exception
''slotlink between two phones does not make sense''; ''slotlink between two phones does not make sense'';
end if; end if;
if link in (''PHHS'', ''HSPH'') then if link in (''PHHS'', ''HSPH'') then
raise exception raise exception
''link of phone to hub does not make sense''; ''link of phone to hub does not make sense'';
end if; end if;
if link in (''PHIF'', ''IFPH'') then if link in (''PHIF'', ''IFPH'') then
raise exception raise exception
''link of phone to hub does not make sense''; ''link of phone to hub does not make sense'';
end if; end if;
if link in (''PSWS'', ''WSPS'') then if link in (''PSWS'', ''WSPS'') then
raise exception raise exception
''slotlink from patchslot to wallslot not permitted''; ''slotlink from patchslot to wallslot not permitted'';
end if; end if;
if mytype = ''PS'' then if mytype = ''PS'' then
...@@ -680,7 +795,11 @@ begin ...@@ -680,7 +795,11 @@ begin
raise exception ''illegal slotlink beginning with %'', mytype; raise exception ''illegal slotlink beginning with %'', mytype;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create function tg_slotlink_unset(bpchar, bpchar) -- ************************************************************
-- * Support function to clear out the slotlink field if
-- * it still points to specific slot
-- ************************************************************
create function tg_slotlink_unset(bpchar, bpchar)
returns integer as ' returns integer as '
declare declare
myname alias for $1; myname alias for $1;
...@@ -741,7 +860,10 @@ begin ...@@ -741,7 +860,10 @@ begin
end if; end if;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create function pslot_backlink_view(bpchar) -- ************************************************************
-- * Describe the backside of a patchfield slot
-- ************************************************************
create function pslot_backlink_view(bpchar)
returns text as ' returns text as '
<<outer>> <<outer>>
declare declare
...@@ -781,7 +903,10 @@ begin ...@@ -781,7 +903,10 @@ begin
return rec.backlink; return rec.backlink;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create function pslot_slotlink_view(bpchar) -- ************************************************************
-- * Describe the front of a patchfield slot
-- ************************************************************
create function pslot_slotlink_view(bpchar)
returns text as ' returns text as '
declare declare
psrec record; psrec record;
...@@ -812,7 +937,10 @@ begin ...@@ -812,7 +937,10 @@ begin
return psrec.slotlink; return psrec.slotlink;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create function wslot_slotlink_view(bpchar) -- ************************************************************
-- * Describe the front of a wall connector slot
-- ************************************************************
create function wslot_slotlink_view(bpchar)
returns text as ' returns text as '
declare declare
rec record; rec record;
...@@ -857,480 +985,535 @@ begin ...@@ -857,480 +985,535 @@ begin
return rec.slotlink; return rec.slotlink;
end; end;
' language 'plpgsql'; ' language 'plpgsql';
QUERY: create view Pfield_v1 as select PF.pfname, PF.slotname, -- ************************************************************
-- * View of a patchfield describing backside and patches
-- ************************************************************
create view Pfield_v1 as select PF.pfname, PF.slotname,
pslot_backlink_view(PF.slotname) as backside, pslot_backlink_view(PF.slotname) as backside,
pslot_slotlink_view(PF.slotname) as patch pslot_slotlink_view(PF.slotname) as patch
from PSlot PF; from PSlot PF;
QUERY: insert into Room values ('001', 'Entrance'); --
QUERY: insert into Room values ('002', 'Office'); -- First we build the house - so we create the rooms
QUERY: insert into Room values ('003', 'Office'); --
QUERY: insert into Room values ('004', 'Technical'); insert into Room values ('001', 'Entrance');
QUERY: insert into Room values ('101', 'Office'); insert into Room values ('002', 'Office');
QUERY: insert into Room values ('102', 'Conference'); insert into Room values ('003', 'Office');
QUERY: insert into Room values ('103', 'Restroom'); insert into Room values ('004', 'Technical');
QUERY: insert into Room values ('104', 'Technical'); insert into Room values ('101', 'Office');
QUERY: insert into Room values ('105', 'Office'); insert into Room values ('102', 'Conference');
QUERY: insert into Room values ('106', 'Office'); insert into Room values ('103', 'Restroom');
QUERY: insert into WSlot values ('WS.001.1a', '001', '', ''); insert into Room values ('104', 'Technical');
QUERY: insert into WSlot values ('WS.001.1b', '001', '', ''); insert into Room values ('105', 'Office');
QUERY: insert into WSlot values ('WS.001.2a', '001', '', ''); insert into Room values ('106', 'Office');
QUERY: insert into WSlot values ('WS.001.2b', '001', '', ''); --
QUERY: insert into WSlot values ('WS.001.3a', '001', '', ''); -- Second we install the wall connectors
QUERY: insert into WSlot values ('WS.001.3b', '001', '', ''); --
QUERY: insert into WSlot values ('WS.002.1a', '002', '', ''); insert into WSlot values ('WS.001.1a', '001', '', '');
QUERY: insert into WSlot values ('WS.002.1b', '002', '', ''); insert into WSlot values ('WS.001.1b', '001', '', '');
QUERY: insert into WSlot values ('WS.002.2a', '002', '', ''); insert into WSlot values ('WS.001.2a', '001', '', '');
QUERY: insert into WSlot values ('WS.002.2b', '002', '', ''); insert into WSlot values ('WS.001.2b', '001', '', '');
QUERY: insert into WSlot values ('WS.002.3a', '002', '', ''); insert into WSlot values ('WS.001.3a', '001', '', '');
QUERY: insert into WSlot values ('WS.002.3b', '002', '', ''); insert into WSlot values ('WS.001.3b', '001', '', '');
QUERY: insert into WSlot values ('WS.003.1a', '003', '', ''); insert into WSlot values ('WS.002.1a', '002', '', '');
QUERY: insert into WSlot values ('WS.003.1b', '003', '', ''); insert into WSlot values ('WS.002.1b', '002', '', '');
QUERY: insert into WSlot values ('WS.003.2a', '003', '', ''); insert into WSlot values ('WS.002.2a', '002', '', '');
QUERY: insert into WSlot values ('WS.003.2b', '003', '', ''); insert into WSlot values ('WS.002.2b', '002', '', '');
QUERY: insert into WSlot values ('WS.003.3a', '003', '', ''); insert into WSlot values ('WS.002.3a', '002', '', '');
QUERY: insert into WSlot values ('WS.003.3b', '003', '', ''); insert into WSlot values ('WS.002.3b', '002', '', '');
QUERY: insert into WSlot values ('WS.101.1a', '101', '', ''); insert into WSlot values ('WS.003.1a', '003', '', '');
QUERY: insert into WSlot values ('WS.101.1b', '101', '', ''); insert into WSlot values ('WS.003.1b', '003', '', '');
QUERY: insert into WSlot values ('WS.101.2a', '101', '', ''); insert into WSlot values ('WS.003.2a', '003', '', '');
QUERY: insert into WSlot values ('WS.101.2b', '101', '', ''); insert into WSlot values ('WS.003.2b', '003', '', '');
QUERY: insert into WSlot values ('WS.101.3a', '101', '', ''); insert into WSlot values ('WS.003.3a', '003', '', '');
QUERY: insert into WSlot values ('WS.101.3b', '101', '', ''); insert into WSlot values ('WS.003.3b', '003', '', '');
QUERY: insert into WSlot values ('WS.102.1a', '102', '', ''); insert into WSlot values ('WS.101.1a', '101', '', '');
QUERY: insert into WSlot values ('WS.102.1b', '102', '', ''); insert into WSlot values ('WS.101.1b', '101', '', '');
QUERY: insert into WSlot values ('WS.102.2a', '102', '', ''); insert into WSlot values ('WS.101.2a', '101', '', '');
QUERY: insert into WSlot values ('WS.102.2b', '102', '', ''); insert into WSlot values ('WS.101.2b', '101', '', '');
QUERY: insert into WSlot values ('WS.102.3a', '102', '', ''); insert into WSlot values ('WS.101.3a', '101', '', '');
QUERY: insert into WSlot values ('WS.102.3b', '102', '', ''); insert into WSlot values ('WS.101.3b', '101', '', '');
QUERY: insert into WSlot values ('WS.105.1a', '105', '', ''); insert into WSlot values ('WS.102.1a', '102', '', '');
QUERY: insert into WSlot values ('WS.105.1b', '105', '', ''); insert into WSlot values ('WS.102.1b', '102', '', '');
QUERY: insert into WSlot values ('WS.105.2a', '105', '', ''); insert into WSlot values ('WS.102.2a', '102', '', '');
QUERY: insert into WSlot values ('WS.105.2b', '105', '', ''); insert into WSlot values ('WS.102.2b', '102', '', '');
QUERY: insert into WSlot values ('WS.105.3a', '105', '', ''); insert into WSlot values ('WS.102.3a', '102', '', '');
QUERY: insert into WSlot values ('WS.105.3b', '105', '', ''); insert into WSlot values ('WS.102.3b', '102', '', '');
QUERY: insert into WSlot values ('WS.106.1a', '106', '', ''); insert into WSlot values ('WS.105.1a', '105', '', '');
QUERY: insert into WSlot values ('WS.106.1b', '106', '', ''); insert into WSlot values ('WS.105.1b', '105', '', '');
QUERY: insert into WSlot values ('WS.106.2a', '106', '', ''); insert into WSlot values ('WS.105.2a', '105', '', '');
QUERY: insert into WSlot values ('WS.106.2b', '106', '', ''); insert into WSlot values ('WS.105.2b', '105', '', '');
QUERY: insert into WSlot values ('WS.106.3a', '106', '', ''); insert into WSlot values ('WS.105.3a', '105', '', '');
QUERY: insert into WSlot values ('WS.106.3b', '106', '', ''); insert into WSlot values ('WS.105.3b', '105', '', '');
QUERY: insert into PField values ('PF0_1', 'Wallslots basement'); insert into WSlot values ('WS.106.1a', '106', '', '');
QUERY: insert into PSlot values ('PS.base.a1', 'PF0_1', '', ''); insert into WSlot values ('WS.106.1b', '106', '', '');
QUERY: insert into PSlot values ('PS.base.a2', 'PF0_1', '', ''); insert into WSlot values ('WS.106.2a', '106', '', '');
QUERY: insert into PSlot values ('PS.base.a3', 'PF0_1', '', ''); insert into WSlot values ('WS.106.2b', '106', '', '');
QUERY: insert into PSlot values ('PS.base.a4', 'PF0_1', '', ''); insert into WSlot values ('WS.106.3a', '106', '', '');
QUERY: insert into PSlot values ('PS.base.a5', 'PF0_1', '', ''); insert into WSlot values ('WS.106.3b', '106', '', '');
QUERY: insert into PSlot values ('PS.base.a6', 'PF0_1', '', ''); --
QUERY: insert into PSlot values ('PS.base.b1', 'PF0_1', '', 'WS.002.1a'); -- Now create the patch fields and their slots
QUERY: insert into PSlot values ('PS.base.b2', 'PF0_1', '', 'WS.002.1b'); --
QUERY: insert into PSlot values ('PS.base.b3', 'PF0_1', '', 'WS.002.2a'); insert into PField values ('PF0_1', 'Wallslots basement');
QUERY: insert into PSlot values ('PS.base.b4', 'PF0_1', '', 'WS.002.2b'); --
QUERY: insert into PSlot values ('PS.base.b5', 'PF0_1', '', 'WS.002.3a'); -- The cables for these will be made later, so they are unconnected for now
QUERY: insert into PSlot values ('PS.base.b6', 'PF0_1', '', 'WS.002.3b'); --
QUERY: insert into PSlot values ('PS.base.c1', 'PF0_1', '', 'WS.003.1a'); insert into PSlot values ('PS.base.a1', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.c2', 'PF0_1', '', 'WS.003.1b'); insert into PSlot values ('PS.base.a2', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.c3', 'PF0_1', '', 'WS.003.2a'); insert into PSlot values ('PS.base.a3', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.c4', 'PF0_1', '', 'WS.003.2b'); insert into PSlot values ('PS.base.a4', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.c5', 'PF0_1', '', 'WS.003.3a'); insert into PSlot values ('PS.base.a5', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.c6', 'PF0_1', '', 'WS.003.3b'); insert into PSlot values ('PS.base.a6', 'PF0_1', '', '');
QUERY: insert into PField values ('PF0_X', 'Phonelines basement'); --
QUERY: insert into PSlot values ('PS.base.ta1', 'PF0_X', '', ''); -- These are already wired to the wall connectors
QUERY: insert into PSlot values ('PS.base.ta2', 'PF0_X', '', ''); --
QUERY: insert into PSlot values ('PS.base.ta3', 'PF0_X', '', ''); insert into PSlot values ('PS.base.b1', 'PF0_1', '', 'WS.002.1a');
QUERY: insert into PSlot values ('PS.base.ta4', 'PF0_X', '', ''); insert into PSlot values ('PS.base.b2', 'PF0_1', '', 'WS.002.1b');
QUERY: insert into PSlot values ('PS.base.ta5', 'PF0_X', '', ''); insert into PSlot values ('PS.base.b3', 'PF0_1', '', 'WS.002.2a');
QUERY: insert into PSlot values ('PS.base.ta6', 'PF0_X', '', ''); insert into PSlot values ('PS.base.b4', 'PF0_1', '', 'WS.002.2b');
QUERY: insert into PSlot values ('PS.base.tb1', 'PF0_X', '', ''); insert into PSlot values ('PS.base.b5', 'PF0_1', '', 'WS.002.3a');
QUERY: insert into PSlot values ('PS.base.tb2', 'PF0_X', '', ''); insert into PSlot values ('PS.base.b6', 'PF0_1', '', 'WS.002.3b');
QUERY: insert into PSlot values ('PS.base.tb3', 'PF0_X', '', ''); insert into PSlot values ('PS.base.c1', 'PF0_1', '', 'WS.003.1a');
QUERY: insert into PSlot values ('PS.base.tb4', 'PF0_X', '', ''); insert into PSlot values ('PS.base.c2', 'PF0_1', '', 'WS.003.1b');
QUERY: insert into PSlot values ('PS.base.tb5', 'PF0_X', '', ''); insert into PSlot values ('PS.base.c3', 'PF0_1', '', 'WS.003.2a');
QUERY: insert into PSlot values ('PS.base.tb6', 'PF0_X', '', ''); insert into PSlot values ('PS.base.c4', 'PF0_1', '', 'WS.003.2b');
QUERY: insert into PField values ('PF1_1', 'Wallslots 1st floor'); insert into PSlot values ('PS.base.c5', 'PF0_1', '', 'WS.003.3a');
QUERY: insert into PSlot values ('PS.1st.a1', 'PF1_1', '', 'WS.101.1a'); insert into PSlot values ('PS.base.c6', 'PF0_1', '', 'WS.003.3b');
QUERY: insert into PSlot values ('PS.1st.a2', 'PF1_1', '', 'WS.101.1b'); --
QUERY: insert into PSlot values ('PS.1st.a3', 'PF1_1', '', 'WS.101.2a'); -- This patchfield will be renamed later into PF0_2 - so its
QUERY: insert into PSlot values ('PS.1st.a4', 'PF1_1', '', 'WS.101.2b'); -- slots references in pfname should follow
QUERY: insert into PSlot values ('PS.1st.a5', 'PF1_1', '', 'WS.101.3a'); --
QUERY: insert into PSlot values ('PS.1st.a6', 'PF1_1', '', 'WS.101.3b'); insert into PField values ('PF0_X', 'Phonelines basement');
QUERY: insert into PSlot values ('PS.1st.b1', 'PF1_1', '', 'WS.102.1a'); insert into PSlot values ('PS.base.ta1', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.b2', 'PF1_1', '', 'WS.102.1b'); insert into PSlot values ('PS.base.ta2', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.b3', 'PF1_1', '', 'WS.102.2a'); insert into PSlot values ('PS.base.ta3', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.b4', 'PF1_1', '', 'WS.102.2b'); insert into PSlot values ('PS.base.ta4', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.b5', 'PF1_1', '', 'WS.102.3a'); insert into PSlot values ('PS.base.ta5', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.b6', 'PF1_1', '', 'WS.102.3b'); insert into PSlot values ('PS.base.ta6', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.c1', 'PF1_1', '', 'WS.105.1a'); insert into PSlot values ('PS.base.tb1', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.c2', 'PF1_1', '', 'WS.105.1b'); insert into PSlot values ('PS.base.tb2', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.c3', 'PF1_1', '', 'WS.105.2a'); insert into PSlot values ('PS.base.tb3', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.c4', 'PF1_1', '', 'WS.105.2b'); insert into PSlot values ('PS.base.tb4', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.c5', 'PF1_1', '', 'WS.105.3a'); insert into PSlot values ('PS.base.tb5', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.c6', 'PF1_1', '', 'WS.105.3b'); insert into PSlot values ('PS.base.tb6', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.1st.d1', 'PF1_1', '', 'WS.106.1a'); insert into PField values ('PF1_1', 'Wallslots 1st floor');
QUERY: insert into PSlot values ('PS.1st.d2', 'PF1_1', '', 'WS.106.1b'); insert into PSlot values ('PS.1st.a1', 'PF1_1', '', 'WS.101.1a');
QUERY: insert into PSlot values ('PS.1st.d3', 'PF1_1', '', 'WS.106.2a'); insert into PSlot values ('PS.1st.a2', 'PF1_1', '', 'WS.101.1b');
QUERY: insert into PSlot values ('PS.1st.d4', 'PF1_1', '', 'WS.106.2b'); insert into PSlot values ('PS.1st.a3', 'PF1_1', '', 'WS.101.2a');
QUERY: insert into PSlot values ('PS.1st.d5', 'PF1_1', '', 'WS.106.3a'); insert into PSlot values ('PS.1st.a4', 'PF1_1', '', 'WS.101.2b');
QUERY: insert into PSlot values ('PS.1st.d6', 'PF1_1', '', 'WS.106.3b'); insert into PSlot values ('PS.1st.a5', 'PF1_1', '', 'WS.101.3a');
QUERY: update PSlot set backlink = 'WS.001.1a' where slotname = 'PS.base.a1'; insert into PSlot values ('PS.1st.a6', 'PF1_1', '', 'WS.101.3b');
QUERY: update PSlot set backlink = 'WS.001.1b' where slotname = 'PS.base.a3'; insert into PSlot values ('PS.1st.b1', 'PF1_1', '', 'WS.102.1a');
QUERY: select * from WSlot where roomno = '001' order by slotname; insert into PSlot values ('PS.1st.b2', 'PF1_1', '', 'WS.102.1b');
slotname |roomno |slotlink |backlink insert into PSlot values ('PS.1st.b3', 'PF1_1', '', 'WS.102.2a');
--------------------+--------+--------------------+-------------------- insert into PSlot values ('PS.1st.b4', 'PF1_1', '', 'WS.102.2b');
WS.001.1a |001 | |PS.base.a1 insert into PSlot values ('PS.1st.b5', 'PF1_1', '', 'WS.102.3a');
WS.001.1b |001 | |PS.base.a3 insert into PSlot values ('PS.1st.b6', 'PF1_1', '', 'WS.102.3b');
WS.001.2a |001 | | insert into PSlot values ('PS.1st.c1', 'PF1_1', '', 'WS.105.1a');
WS.001.2b |001 | | insert into PSlot values ('PS.1st.c2', 'PF1_1', '', 'WS.105.1b');
WS.001.3a |001 | | insert into PSlot values ('PS.1st.c3', 'PF1_1', '', 'WS.105.2a');
WS.001.3b |001 | | insert into PSlot values ('PS.1st.c4', 'PF1_1', '', 'WS.105.2b');
insert into PSlot values ('PS.1st.c5', 'PF1_1', '', 'WS.105.3a');
insert into PSlot values ('PS.1st.c6', 'PF1_1', '', 'WS.105.3b');
insert into PSlot values ('PS.1st.d1', 'PF1_1', '', 'WS.106.1a');
insert into PSlot values ('PS.1st.d2', 'PF1_1', '', 'WS.106.1b');
insert into PSlot values ('PS.1st.d3', 'PF1_1', '', 'WS.106.2a');
insert into PSlot values ('PS.1st.d4', 'PF1_1', '', 'WS.106.2b');
insert into PSlot values ('PS.1st.d5', 'PF1_1', '', 'WS.106.3a');
insert into PSlot values ('PS.1st.d6', 'PF1_1', '', 'WS.106.3b');
--
-- Now we wire the wall connectors 1a-2a in room 001 to the
-- patchfield. In the second update we make an error, and
-- correct it after
--
update PSlot set backlink = 'WS.001.1a' where slotname = 'PS.base.a1';
update PSlot set backlink = 'WS.001.1b' where slotname = 'PS.base.a3';
select * from WSlot where roomno = '001' order by slotname;
slotname | roomno | slotlink | backlink
----------------------+----------+----------------------+----------------------
WS.001.1a | 001 | | PS.base.a1
WS.001.1b | 001 | | PS.base.a3
WS.001.2a | 001 | |
WS.001.2b | 001 | |
WS.001.3a | 001 | |
WS.001.3b | 001 | |
(6 rows) (6 rows)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname; select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink slotname | pfname | slotlink | backlink
--------------------+------+--------------------+-------------------- ----------------------+--------+----------------------+----------------------
PS.base.a1 |PF0_1 | |WS.001.1a PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 |PF0_1 | | PS.base.a2 | PF0_1 | |
PS.base.a3 |PF0_1 | |WS.001.1b PS.base.a3 | PF0_1 | | WS.001.1b
PS.base.a4 |PF0_1 | | PS.base.a4 | PF0_1 | |
PS.base.a5 |PF0_1 | | PS.base.a5 | PF0_1 | |
PS.base.a6 |PF0_1 | | PS.base.a6 | PF0_1 | |
(6 rows) (6 rows)
QUERY: update PSlot set backlink = 'WS.001.2a' where slotname = 'PS.base.a3'; update PSlot set backlink = 'WS.001.2a' where slotname = 'PS.base.a3';
QUERY: select * from WSlot where roomno = '001' order by slotname; select * from WSlot where roomno = '001' order by slotname;
slotname |roomno |slotlink |backlink slotname | roomno | slotlink | backlink
--------------------+--------+--------------------+-------------------- ----------------------+----------+----------------------+----------------------
WS.001.1a |001 | |PS.base.a1 WS.001.1a | 001 | | PS.base.a1
WS.001.1b |001 | | WS.001.1b | 001 | |
WS.001.2a |001 | |PS.base.a3 WS.001.2a | 001 | | PS.base.a3
WS.001.2b |001 | | WS.001.2b | 001 | |
WS.001.3a |001 | | WS.001.3a | 001 | |
WS.001.3b |001 | | WS.001.3b | 001 | |
(6 rows) (6 rows)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname; select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink slotname | pfname | slotlink | backlink
--------------------+------+--------------------+-------------------- ----------------------+--------+----------------------+----------------------
PS.base.a1 |PF0_1 | |WS.001.1a PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 |PF0_1 | | PS.base.a2 | PF0_1 | |
PS.base.a3 |PF0_1 | |WS.001.2a PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 |PF0_1 | | PS.base.a4 | PF0_1 | |
PS.base.a5 |PF0_1 | | PS.base.a5 | PF0_1 | |
PS.base.a6 |PF0_1 | | PS.base.a6 | PF0_1 | |
(6 rows) (6 rows)
QUERY: update PSlot set backlink = 'WS.001.1b' where slotname = 'PS.base.a2'; update PSlot set backlink = 'WS.001.1b' where slotname = 'PS.base.a2';
QUERY: select * from WSlot where roomno = '001' order by slotname; select * from WSlot where roomno = '001' order by slotname;
slotname |roomno |slotlink |backlink slotname | roomno | slotlink | backlink
--------------------+--------+--------------------+-------------------- ----------------------+----------+----------------------+----------------------
WS.001.1a |001 | |PS.base.a1 WS.001.1a | 001 | | PS.base.a1
WS.001.1b |001 | |PS.base.a2 WS.001.1b | 001 | | PS.base.a2
WS.001.2a |001 | |PS.base.a3 WS.001.2a | 001 | | PS.base.a3
WS.001.2b |001 | | WS.001.2b | 001 | |
WS.001.3a |001 | | WS.001.3a | 001 | |
WS.001.3b |001 | | WS.001.3b | 001 | |
(6 rows) (6 rows)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname; select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink slotname | pfname | slotlink | backlink
--------------------+------+--------------------+-------------------- ----------------------+--------+----------------------+----------------------
PS.base.a1 |PF0_1 | |WS.001.1a PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 |PF0_1 | |WS.001.1b PS.base.a2 | PF0_1 | | WS.001.1b
PS.base.a3 |PF0_1 | |WS.001.2a PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 |PF0_1 | | PS.base.a4 | PF0_1 | |
PS.base.a5 |PF0_1 | | PS.base.a5 | PF0_1 | |
PS.base.a6 |PF0_1 | | PS.base.a6 | PF0_1 | |
(6 rows) (6 rows)
QUERY: update WSlot set backlink = 'PS.base.a4' where slotname = 'WS.001.2b'; --
QUERY: update WSlot set backlink = 'PS.base.a6' where slotname = 'WS.001.3a'; -- Same procedure for 2b-3b but this time updating the WSlot instead
QUERY: select * from WSlot where roomno = '001' order by slotname; -- of the PSlot. Due to the triggers the result is the same:
slotname |roomno |slotlink |backlink -- WSlot and corresponding PSlot point to each other.
--------------------+--------+--------------------+-------------------- --
WS.001.1a |001 | |PS.base.a1 update WSlot set backlink = 'PS.base.a4' where slotname = 'WS.001.2b';
WS.001.1b |001 | |PS.base.a2 update WSlot set backlink = 'PS.base.a6' where slotname = 'WS.001.3a';
WS.001.2a |001 | |PS.base.a3 select * from WSlot where roomno = '001' order by slotname;
WS.001.2b |001 | |PS.base.a4 slotname | roomno | slotlink | backlink
WS.001.3a |001 | |PS.base.a6 ----------------------+----------+----------------------+----------------------
WS.001.3b |001 | | WS.001.1a | 001 | | PS.base.a1
WS.001.1b | 001 | | PS.base.a2
WS.001.2a | 001 | | PS.base.a3
WS.001.2b | 001 | | PS.base.a4
WS.001.3a | 001 | | PS.base.a6
WS.001.3b | 001 | |
(6 rows) (6 rows)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname; select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink slotname | pfname | slotlink | backlink
--------------------+------+--------------------+-------------------- ----------------------+--------+----------------------+----------------------
PS.base.a1 |PF0_1 | |WS.001.1a PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 |PF0_1 | |WS.001.1b PS.base.a2 | PF0_1 | | WS.001.1b
PS.base.a3 |PF0_1 | |WS.001.2a PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 |PF0_1 | |WS.001.2b PS.base.a4 | PF0_1 | | WS.001.2b
PS.base.a5 |PF0_1 | | PS.base.a5 | PF0_1 | |
PS.base.a6 |PF0_1 | |WS.001.3a PS.base.a6 | PF0_1 | | WS.001.3a
(6 rows) (6 rows)
QUERY: update WSlot set backlink = 'PS.base.a6' where slotname = 'WS.001.3b'; update WSlot set backlink = 'PS.base.a6' where slotname = 'WS.001.3b';
QUERY: select * from WSlot where roomno = '001' order by slotname; select * from WSlot where roomno = '001' order by slotname;
slotname |roomno |slotlink |backlink slotname | roomno | slotlink | backlink
--------------------+--------+--------------------+-------------------- ----------------------+----------+----------------------+----------------------
WS.001.1a |001 | |PS.base.a1 WS.001.1a | 001 | | PS.base.a1
WS.001.1b |001 | |PS.base.a2 WS.001.1b | 001 | | PS.base.a2
WS.001.2a |001 | |PS.base.a3 WS.001.2a | 001 | | PS.base.a3
WS.001.2b |001 | |PS.base.a4 WS.001.2b | 001 | | PS.base.a4
WS.001.3a |001 | | WS.001.3a | 001 | |
WS.001.3b |001 | |PS.base.a6 WS.001.3b | 001 | | PS.base.a6
(6 rows) (6 rows)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname; select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink slotname | pfname | slotlink | backlink
--------------------+------+--------------------+-------------------- ----------------------+--------+----------------------+----------------------
PS.base.a1 |PF0_1 | |WS.001.1a PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 |PF0_1 | |WS.001.1b PS.base.a2 | PF0_1 | | WS.001.1b
PS.base.a3 |PF0_1 | |WS.001.2a PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 |PF0_1 | |WS.001.2b PS.base.a4 | PF0_1 | | WS.001.2b
PS.base.a5 |PF0_1 | | PS.base.a5 | PF0_1 | |
PS.base.a6 |PF0_1 | |WS.001.3b PS.base.a6 | PF0_1 | | WS.001.3b
(6 rows) (6 rows)
QUERY: update WSlot set backlink = 'PS.base.a5' where slotname = 'WS.001.3a'; update WSlot set backlink = 'PS.base.a5' where slotname = 'WS.001.3a';
QUERY: select * from WSlot where roomno = '001' order by slotname; select * from WSlot where roomno = '001' order by slotname;
slotname |roomno |slotlink |backlink slotname | roomno | slotlink | backlink
--------------------+--------+--------------------+-------------------- ----------------------+----------+----------------------+----------------------
WS.001.1a |001 | |PS.base.a1 WS.001.1a | 001 | | PS.base.a1
WS.001.1b |001 | |PS.base.a2 WS.001.1b | 001 | | PS.base.a2
WS.001.2a |001 | |PS.base.a3 WS.001.2a | 001 | | PS.base.a3
WS.001.2b |001 | |PS.base.a4 WS.001.2b | 001 | | PS.base.a4
WS.001.3a |001 | |PS.base.a5 WS.001.3a | 001 | | PS.base.a5
WS.001.3b |001 | |PS.base.a6 WS.001.3b | 001 | | PS.base.a6
(6 rows) (6 rows)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname; select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink slotname | pfname | slotlink | backlink
--------------------+------+--------------------+-------------------- ----------------------+--------+----------------------+----------------------
PS.base.a1 |PF0_1 | |WS.001.1a PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 |PF0_1 | |WS.001.1b PS.base.a2 | PF0_1 | | WS.001.1b
PS.base.a3 |PF0_1 | |WS.001.2a PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 |PF0_1 | |WS.001.2b PS.base.a4 | PF0_1 | | WS.001.2b
PS.base.a5 |PF0_1 | |WS.001.3a PS.base.a5 | PF0_1 | | WS.001.3a
PS.base.a6 |PF0_1 | |WS.001.3b PS.base.a6 | PF0_1 | | WS.001.3b
(6 rows) (6 rows)
QUERY: insert into PField values ('PF1_2', 'Phonelines 1st floor'); insert into PField values ('PF1_2', 'Phonelines 1st floor');
QUERY: insert into PSlot values ('PS.1st.ta1', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.ta1', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.ta2', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.ta2', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.ta3', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.ta3', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.ta4', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.ta4', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.ta5', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.ta5', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.ta6', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.ta6', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb1', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.tb1', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb2', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.tb2', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb3', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.tb3', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb4', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.tb4', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb5', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.tb5', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb6', 'PF1_2', '', ''); insert into PSlot values ('PS.1st.tb6', 'PF1_2', '', '');
QUERY: update PField set name = 'PF0_2' where name = 'PF0_X'; --
QUERY: select * from PSlot order by slotname; -- Fix the wrong name for patchfield PF0_2
slotname |pfname|slotlink |backlink --
--------------------+------+--------------------+-------------------- update PField set name = 'PF0_2' where name = 'PF0_X';
PS.1st.a1 |PF1_1 | |WS.101.1a select * from PSlot order by slotname;
PS.1st.a2 |PF1_1 | |WS.101.1b slotname | pfname | slotlink | backlink
PS.1st.a3 |PF1_1 | |WS.101.2a ----------------------+--------+----------------------+----------------------
PS.1st.a4 |PF1_1 | |WS.101.2b PS.1st.a1 | PF1_1 | | WS.101.1a
PS.1st.a5 |PF1_1 | |WS.101.3a PS.1st.a2 | PF1_1 | | WS.101.1b
PS.1st.a6 |PF1_1 | |WS.101.3b PS.1st.a3 | PF1_1 | | WS.101.2a
PS.1st.b1 |PF1_1 | |WS.102.1a PS.1st.a4 | PF1_1 | | WS.101.2b
PS.1st.b2 |PF1_1 | |WS.102.1b PS.1st.a5 | PF1_1 | | WS.101.3a
PS.1st.b3 |PF1_1 | |WS.102.2a PS.1st.a6 | PF1_1 | | WS.101.3b
PS.1st.b4 |PF1_1 | |WS.102.2b PS.1st.b1 | PF1_1 | | WS.102.1a
PS.1st.b5 |PF1_1 | |WS.102.3a PS.1st.b2 | PF1_1 | | WS.102.1b
PS.1st.b6 |PF1_1 | |WS.102.3b PS.1st.b3 | PF1_1 | | WS.102.2a
PS.1st.c1 |PF1_1 | |WS.105.1a PS.1st.b4 | PF1_1 | | WS.102.2b
PS.1st.c2 |PF1_1 | |WS.105.1b PS.1st.b5 | PF1_1 | | WS.102.3a
PS.1st.c3 |PF1_1 | |WS.105.2a PS.1st.b6 | PF1_1 | | WS.102.3b
PS.1st.c4 |PF1_1 | |WS.105.2b PS.1st.c1 | PF1_1 | | WS.105.1a
PS.1st.c5 |PF1_1 | |WS.105.3a PS.1st.c2 | PF1_1 | | WS.105.1b
PS.1st.c6 |PF1_1 | |WS.105.3b PS.1st.c3 | PF1_1 | | WS.105.2a
PS.1st.d1 |PF1_1 | |WS.106.1a PS.1st.c4 | PF1_1 | | WS.105.2b
PS.1st.d2 |PF1_1 | |WS.106.1b PS.1st.c5 | PF1_1 | | WS.105.3a
PS.1st.d3 |PF1_1 | |WS.106.2a PS.1st.c6 | PF1_1 | | WS.105.3b
PS.1st.d4 |PF1_1 | |WS.106.2b PS.1st.d1 | PF1_1 | | WS.106.1a
PS.1st.d5 |PF1_1 | |WS.106.3a PS.1st.d2 | PF1_1 | | WS.106.1b
PS.1st.d6 |PF1_1 | |WS.106.3b PS.1st.d3 | PF1_1 | | WS.106.2a
PS.1st.ta1 |PF1_2 | | PS.1st.d4 | PF1_1 | | WS.106.2b
PS.1st.ta2 |PF1_2 | | PS.1st.d5 | PF1_1 | | WS.106.3a
PS.1st.ta3 |PF1_2 | | PS.1st.d6 | PF1_1 | | WS.106.3b
PS.1st.ta4 |PF1_2 | | PS.1st.ta1 | PF1_2 | |
PS.1st.ta5 |PF1_2 | | PS.1st.ta2 | PF1_2 | |
PS.1st.ta6 |PF1_2 | | PS.1st.ta3 | PF1_2 | |
PS.1st.tb1 |PF1_2 | | PS.1st.ta4 | PF1_2 | |
PS.1st.tb2 |PF1_2 | | PS.1st.ta5 | PF1_2 | |
PS.1st.tb3 |PF1_2 | | PS.1st.ta6 | PF1_2 | |
PS.1st.tb4 |PF1_2 | | PS.1st.tb1 | PF1_2 | |
PS.1st.tb5 |PF1_2 | | PS.1st.tb2 | PF1_2 | |
PS.1st.tb6 |PF1_2 | | PS.1st.tb3 | PF1_2 | |
PS.base.a1 |PF0_1 | |WS.001.1a PS.1st.tb4 | PF1_2 | |
PS.base.a2 |PF0_1 | |WS.001.1b PS.1st.tb5 | PF1_2 | |
PS.base.a3 |PF0_1 | |WS.001.2a PS.1st.tb6 | PF1_2 | |
PS.base.a4 |PF0_1 | |WS.001.2b PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a5 |PF0_1 | |WS.001.3a PS.base.a2 | PF0_1 | | WS.001.1b
PS.base.a6 |PF0_1 | |WS.001.3b PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.b1 |PF0_1 | |WS.002.1a PS.base.a4 | PF0_1 | | WS.001.2b
PS.base.b2 |PF0_1 | |WS.002.1b PS.base.a5 | PF0_1 | | WS.001.3a
PS.base.b3 |PF0_1 | |WS.002.2a PS.base.a6 | PF0_1 | | WS.001.3b
PS.base.b4 |PF0_1 | |WS.002.2b PS.base.b1 | PF0_1 | | WS.002.1a
PS.base.b5 |PF0_1 | |WS.002.3a PS.base.b2 | PF0_1 | | WS.002.1b
PS.base.b6 |PF0_1 | |WS.002.3b PS.base.b3 | PF0_1 | | WS.002.2a
PS.base.c1 |PF0_1 | |WS.003.1a PS.base.b4 | PF0_1 | | WS.002.2b
PS.base.c2 |PF0_1 | |WS.003.1b PS.base.b5 | PF0_1 | | WS.002.3a
PS.base.c3 |PF0_1 | |WS.003.2a PS.base.b6 | PF0_1 | | WS.002.3b
PS.base.c4 |PF0_1 | |WS.003.2b PS.base.c1 | PF0_1 | | WS.003.1a
PS.base.c5 |PF0_1 | |WS.003.3a PS.base.c2 | PF0_1 | | WS.003.1b
PS.base.c6 |PF0_1 | |WS.003.3b PS.base.c3 | PF0_1 | | WS.003.2a
PS.base.ta1 |PF0_2 | | PS.base.c4 | PF0_1 | | WS.003.2b
PS.base.ta2 |PF0_2 | | PS.base.c5 | PF0_1 | | WS.003.3a
PS.base.ta3 |PF0_2 | | PS.base.c6 | PF0_1 | | WS.003.3b
PS.base.ta4 |PF0_2 | | PS.base.ta1 | PF0_2 | |
PS.base.ta5 |PF0_2 | | PS.base.ta2 | PF0_2 | |
PS.base.ta6 |PF0_2 | | PS.base.ta3 | PF0_2 | |
PS.base.tb1 |PF0_2 | | PS.base.ta4 | PF0_2 | |
PS.base.tb2 |PF0_2 | | PS.base.ta5 | PF0_2 | |
PS.base.tb3 |PF0_2 | | PS.base.ta6 | PF0_2 | |
PS.base.tb4 |PF0_2 | | PS.base.tb1 | PF0_2 | |
PS.base.tb5 |PF0_2 | | PS.base.tb2 | PF0_2 | |
PS.base.tb6 |PF0_2 | | PS.base.tb3 | PF0_2 | |
PS.base.tb4 | PF0_2 | |
PS.base.tb5 | PF0_2 | |
PS.base.tb6 | PF0_2 | |
(66 rows) (66 rows)
QUERY: select * from WSlot order by slotname; select * from WSlot order by slotname;
slotname |roomno |slotlink |backlink slotname | roomno | slotlink | backlink
--------------------+--------+--------------------+-------------------- ----------------------+----------+----------------------+----------------------
WS.001.1a |001 | |PS.base.a1 WS.001.1a | 001 | | PS.base.a1
WS.001.1b |001 | |PS.base.a2 WS.001.1b | 001 | | PS.base.a2
WS.001.2a |001 | |PS.base.a3 WS.001.2a | 001 | | PS.base.a3
WS.001.2b |001 | |PS.base.a4 WS.001.2b | 001 | | PS.base.a4
WS.001.3a |001 | |PS.base.a5 WS.001.3a | 001 | | PS.base.a5
WS.001.3b |001 | |PS.base.a6 WS.001.3b | 001 | | PS.base.a6
WS.002.1a |002 | |PS.base.b1 WS.002.1a | 002 | | PS.base.b1
WS.002.1b |002 | |PS.base.b2 WS.002.1b | 002 | | PS.base.b2
WS.002.2a |002 | |PS.base.b3 WS.002.2a | 002 | | PS.base.b3
WS.002.2b |002 | |PS.base.b4 WS.002.2b | 002 | | PS.base.b4
WS.002.3a |002 | |PS.base.b5 WS.002.3a | 002 | | PS.base.b5
WS.002.3b |002 | |PS.base.b6 WS.002.3b | 002 | | PS.base.b6
WS.003.1a |003 | |PS.base.c1 WS.003.1a | 003 | | PS.base.c1
WS.003.1b |003 | |PS.base.c2 WS.003.1b | 003 | | PS.base.c2
WS.003.2a |003 | |PS.base.c3 WS.003.2a | 003 | | PS.base.c3
WS.003.2b |003 | |PS.base.c4 WS.003.2b | 003 | | PS.base.c4
WS.003.3a |003 | |PS.base.c5 WS.003.3a | 003 | | PS.base.c5
WS.003.3b |003 | |PS.base.c6 WS.003.3b | 003 | | PS.base.c6
WS.101.1a |101 | |PS.1st.a1 WS.101.1a | 101 | | PS.1st.a1
WS.101.1b |101 | |PS.1st.a2 WS.101.1b | 101 | | PS.1st.a2
WS.101.2a |101 | |PS.1st.a3 WS.101.2a | 101 | | PS.1st.a3
WS.101.2b |101 | |PS.1st.a4 WS.101.2b | 101 | | PS.1st.a4
WS.101.3a |101 | |PS.1st.a5 WS.101.3a | 101 | | PS.1st.a5
WS.101.3b |101 | |PS.1st.a6 WS.101.3b | 101 | | PS.1st.a6
WS.102.1a |102 | |PS.1st.b1 WS.102.1a | 102 | | PS.1st.b1
WS.102.1b |102 | |PS.1st.b2 WS.102.1b | 102 | | PS.1st.b2
WS.102.2a |102 | |PS.1st.b3 WS.102.2a | 102 | | PS.1st.b3
WS.102.2b |102 | |PS.1st.b4 WS.102.2b | 102 | | PS.1st.b4
WS.102.3a |102 | |PS.1st.b5 WS.102.3a | 102 | | PS.1st.b5
WS.102.3b |102 | |PS.1st.b6 WS.102.3b | 102 | | PS.1st.b6
WS.105.1a |105 | |PS.1st.c1 WS.105.1a | 105 | | PS.1st.c1
WS.105.1b |105 | |PS.1st.c2 WS.105.1b | 105 | | PS.1st.c2
WS.105.2a |105 | |PS.1st.c3 WS.105.2a | 105 | | PS.1st.c3
WS.105.2b |105 | |PS.1st.c4 WS.105.2b | 105 | | PS.1st.c4
WS.105.3a |105 | |PS.1st.c5 WS.105.3a | 105 | | PS.1st.c5
WS.105.3b |105 | |PS.1st.c6 WS.105.3b | 105 | | PS.1st.c6
WS.106.1a |106 | |PS.1st.d1 WS.106.1a | 106 | | PS.1st.d1
WS.106.1b |106 | |PS.1st.d2 WS.106.1b | 106 | | PS.1st.d2
WS.106.2a |106 | |PS.1st.d3 WS.106.2a | 106 | | PS.1st.d3
WS.106.2b |106 | |PS.1st.d4 WS.106.2b | 106 | | PS.1st.d4
WS.106.3a |106 | |PS.1st.d5 WS.106.3a | 106 | | PS.1st.d5
WS.106.3b |106 | |PS.1st.d6 WS.106.3b | 106 | | PS.1st.d6
(42 rows) (42 rows)
QUERY: insert into PLine values ('PL.001', '-0', 'Central call', 'PS.base.ta1'); --
QUERY: insert into PLine values ('PL.002', '-101', '', 'PS.base.ta2'); -- Install the central phone system and create the phone numbers.
QUERY: insert into PLine values ('PL.003', '-102', '', 'PS.base.ta3'); -- They are weired on insert to the patchfields. Again the
QUERY: insert into PLine values ('PL.004', '-103', '', 'PS.base.ta5'); -- triggers automatically tell the PSlots to update their
QUERY: insert into PLine values ('PL.005', '-104', '', 'PS.base.ta6'); -- backlink field.
QUERY: insert into PLine values ('PL.006', '-106', '', 'PS.base.tb2'); --
QUERY: insert into PLine values ('PL.007', '-108', '', 'PS.base.tb3'); insert into PLine values ('PL.001', '-0', 'Central call', 'PS.base.ta1');
QUERY: insert into PLine values ('PL.008', '-109', '', 'PS.base.tb4'); insert into PLine values ('PL.002', '-101', '', 'PS.base.ta2');
QUERY: insert into PLine values ('PL.009', '-121', '', 'PS.base.tb5'); insert into PLine values ('PL.003', '-102', '', 'PS.base.ta3');
QUERY: insert into PLine values ('PL.010', '-122', '', 'PS.base.tb6'); insert into PLine values ('PL.004', '-103', '', 'PS.base.ta5');
QUERY: insert into PLine values ('PL.015', '-134', '', 'PS.1st.ta1'); insert into PLine values ('PL.005', '-104', '', 'PS.base.ta6');
QUERY: insert into PLine values ('PL.016', '-137', '', 'PS.1st.ta3'); insert into PLine values ('PL.006', '-106', '', 'PS.base.tb2');
QUERY: insert into PLine values ('PL.017', '-139', '', 'PS.1st.ta4'); insert into PLine values ('PL.007', '-108', '', 'PS.base.tb3');
QUERY: insert into PLine values ('PL.018', '-362', '', 'PS.1st.tb1'); insert into PLine values ('PL.008', '-109', '', 'PS.base.tb4');
QUERY: insert into PLine values ('PL.019', '-363', '', 'PS.1st.tb2'); insert into PLine values ('PL.009', '-121', '', 'PS.base.tb5');
QUERY: insert into PLine values ('PL.020', '-364', '', 'PS.1st.tb3'); insert into PLine values ('PL.010', '-122', '', 'PS.base.tb6');
QUERY: insert into PLine values ('PL.021', '-365', '', 'PS.1st.tb5'); insert into PLine values ('PL.015', '-134', '', 'PS.1st.ta1');
QUERY: insert into PLine values ('PL.022', '-367', '', 'PS.1st.tb6'); insert into PLine values ('PL.016', '-137', '', 'PS.1st.ta3');
QUERY: insert into PLine values ('PL.028', '-501', 'Fax entrance', 'PS.base.ta2'); insert into PLine values ('PL.017', '-139', '', 'PS.1st.ta4');
QUERY: insert into PLine values ('PL.029', '-502', 'Fax 1st floor', 'PS.1st.ta1'); insert into PLine values ('PL.018', '-362', '', 'PS.1st.tb1');
QUERY: insert into PHone values ('PH.hc001', 'Hicom standard', 'WS.001.1a'); insert into PLine values ('PL.019', '-363', '', 'PS.1st.tb2');
QUERY: update PSlot set slotlink = 'PS.base.ta1' where slotname = 'PS.base.a1'; insert into PLine values ('PL.020', '-364', '', 'PS.1st.tb3');
QUERY: insert into PHone values ('PH.hc002', 'Hicom standard', 'WS.002.1a'); insert into PLine values ('PL.021', '-365', '', 'PS.1st.tb5');
QUERY: update PSlot set slotlink = 'PS.base.ta5' where slotname = 'PS.base.b1'; insert into PLine values ('PL.022', '-367', '', 'PS.1st.tb6');
QUERY: insert into PHone values ('PH.hc003', 'Hicom standard', 'WS.002.2a'); insert into PLine values ('PL.028', '-501', 'Fax entrance', 'PS.base.ta2');
QUERY: update PSlot set slotlink = 'PS.base.tb2' where slotname = 'PS.base.b3'; insert into PLine values ('PL.029', '-502', 'Fax 1st floor', 'PS.1st.ta1');
QUERY: insert into PHone values ('PH.fax001', 'Canon fax', 'WS.001.2a'); --
QUERY: update PSlot set slotlink = 'PS.base.ta2' where slotname = 'PS.base.a3'; -- Buy some phones, plug them into the wall and patch the
QUERY: insert into Hub values ('base.hub1', 'Patchfield PF0_1 hub', 16); -- phone lines to the corresponding patchfield slots.
QUERY: insert into System values ('orion', 'PC'); --
QUERY: insert into IFace values ('IF', 'orion', 'eth0', 'WS.002.1b'); insert into PHone values ('PH.hc001', 'Hicom standard', 'WS.001.1a');
QUERY: update PSlot set slotlink = 'HS.base.hub1.1' where slotname = 'PS.base.b2'; update PSlot set slotlink = 'PS.base.ta1' where slotname = 'PS.base.a1';
QUERY: select * from PField_v1 where pfname = 'PF0_1' order by slotname; insert into PHone values ('PH.hc002', 'Hicom standard', 'WS.002.1a');
pfname|slotname |backside |patch update PSlot set slotlink = 'PS.base.ta5' where slotname = 'PS.base.b1';
------+--------------------+--------------------------------------------------------+--------------------------------------------- insert into PHone values ('PH.hc003', 'Hicom standard', 'WS.002.2a');
PF0_1 |PS.base.a1 |WS.001.1a in room 001 -> Phone PH.hc001 (Hicom standard)|PS.base.ta1 -> Phone line -0 (Central call) update PSlot set slotlink = 'PS.base.tb2' where slotname = 'PS.base.b3';
PF0_1 |PS.base.a2 |WS.001.1b in room 001 -> - |- insert into PHone values ('PH.fax001', 'Canon fax', 'WS.001.2a');
PF0_1 |PS.base.a3 |WS.001.2a in room 001 -> Phone PH.fax001 (Canon fax) |PS.base.ta2 -> Phone line -501 (Fax entrance) update PSlot set slotlink = 'PS.base.ta2' where slotname = 'PS.base.a3';
PF0_1 |PS.base.a4 |WS.001.2b in room 001 -> - |- --
PF0_1 |PS.base.a5 |WS.001.3a in room 001 -> - |- -- Install a hub at one of the patchfields, plug a computers
PF0_1 |PS.base.a6 |WS.001.3b in room 001 -> - |- -- ethernet interface into the wall and patch it to the hub.
PF0_1 |PS.base.b1 |WS.002.1a in room 002 -> Phone PH.hc002 (Hicom standard)|PS.base.ta5 -> Phone line -103 --
PF0_1 |PS.base.b2 |WS.002.1b in room 002 -> orion IF eth0 (PC) |Patchfield PF0_1 hub slot 1 insert into Hub values ('base.hub1', 'Patchfield PF0_1 hub', 16);
PF0_1 |PS.base.b3 |WS.002.2a in room 002 -> Phone PH.hc003 (Hicom standard)|PS.base.tb2 -> Phone line -106 insert into System values ('orion', 'PC');
PF0_1 |PS.base.b4 |WS.002.2b in room 002 -> - |- insert into IFace values ('IF', 'orion', 'eth0', 'WS.002.1b');
PF0_1 |PS.base.b5 |WS.002.3a in room 002 -> - |- update PSlot set slotlink = 'HS.base.hub1.1' where slotname = 'PS.base.b2';
PF0_1 |PS.base.b6 |WS.002.3b in room 002 -> - |- --
PF0_1 |PS.base.c1 |WS.003.1a in room 003 -> - |- -- Now we take a look at the patchfield
PF0_1 |PS.base.c2 |WS.003.1b in room 003 -> - |- --
PF0_1 |PS.base.c3 |WS.003.2a in room 003 -> - |- select * from PField_v1 where pfname = 'PF0_1' order by slotname;
PF0_1 |PS.base.c4 |WS.003.2b in room 003 -> - |- pfname | slotname | backside | patch
PF0_1 |PS.base.c5 |WS.003.3a in room 003 -> - |- --------+----------------------+----------------------------------------------------------+-----------------------------------------------
PF0_1 |PS.base.c6 |WS.003.3b in room 003 -> - |- PF0_1 | PS.base.a1 | WS.001.1a in room 001 -> Phone PH.hc001 (Hicom standard) | PS.base.ta1 -> Phone line -0 (Central call)
PF0_1 | PS.base.a2 | WS.001.1b in room 001 -> - | -
PF0_1 | PS.base.a3 | WS.001.2a in room 001 -> Phone PH.fax001 (Canon fax) | PS.base.ta2 -> Phone line -501 (Fax entrance)
PF0_1 | PS.base.a4 | WS.001.2b in room 001 -> - | -
PF0_1 | PS.base.a5 | WS.001.3a in room 001 -> - | -
PF0_1 | PS.base.a6 | WS.001.3b in room 001 -> - | -
PF0_1 | PS.base.b1 | WS.002.1a in room 002 -> Phone PH.hc002 (Hicom standard) | PS.base.ta5 -> Phone line -103
PF0_1 | PS.base.b2 | WS.002.1b in room 002 -> orion IF eth0 (PC) | Patchfield PF0_1 hub slot 1
PF0_1 | PS.base.b3 | WS.002.2a in room 002 -> Phone PH.hc003 (Hicom standard) | PS.base.tb2 -> Phone line -106
PF0_1 | PS.base.b4 | WS.002.2b in room 002 -> - | -
PF0_1 | PS.base.b5 | WS.002.3a in room 002 -> - | -
PF0_1 | PS.base.b6 | WS.002.3b in room 002 -> - | -
PF0_1 | PS.base.c1 | WS.003.1a in room 003 -> - | -
PF0_1 | PS.base.c2 | WS.003.1b in room 003 -> - | -
PF0_1 | PS.base.c3 | WS.003.2a in room 003 -> - | -
PF0_1 | PS.base.c4 | WS.003.2b in room 003 -> - | -
PF0_1 | PS.base.c5 | WS.003.3a in room 003 -> - | -
PF0_1 | PS.base.c6 | WS.003.3b in room 003 -> - | -
(18 rows) (18 rows)
QUERY: select * from PField_v1 where pfname = 'PF0_2' order by slotname; select * from PField_v1 where pfname = 'PF0_2' order by slotname;
pfname|slotname |backside |patch pfname | slotname | backside | patch
------+--------------------+------------------------------+---------------------------------------------------------------------- --------+----------------------+--------------------------------+------------------------------------------------------------------------
PF0_2 |PS.base.ta1 |Phone line -0 (Central call) |PS.base.a1 -> WS.001.1a in room 001 -> Phone PH.hc001 (Hicom standard) PF0_2 | PS.base.ta1 | Phone line -0 (Central call) | PS.base.a1 -> WS.001.1a in room 001 -> Phone PH.hc001 (Hicom standard)
PF0_2 |PS.base.ta2 |Phone line -501 (Fax entrance)|PS.base.a3 -> WS.001.2a in room 001 -> Phone PH.fax001 (Canon fax) PF0_2 | PS.base.ta2 | Phone line -501 (Fax entrance) | PS.base.a3 -> WS.001.2a in room 001 -> Phone PH.fax001 (Canon fax)
PF0_2 |PS.base.ta3 |Phone line -102 |- PF0_2 | PS.base.ta3 | Phone line -102 | -
PF0_2 |PS.base.ta4 |- |- PF0_2 | PS.base.ta4 | - | -
PF0_2 |PS.base.ta5 |Phone line -103 |PS.base.b1 -> WS.002.1a in room 002 -> Phone PH.hc002 (Hicom standard) PF0_2 | PS.base.ta5 | Phone line -103 | PS.base.b1 -> WS.002.1a in room 002 -> Phone PH.hc002 (Hicom standard)
PF0_2 |PS.base.ta6 |Phone line -104 |- PF0_2 | PS.base.ta6 | Phone line -104 | -
PF0_2 |PS.base.tb1 |- |- PF0_2 | PS.base.tb1 | - | -
PF0_2 |PS.base.tb2 |Phone line -106 |PS.base.b3 -> WS.002.2a in room 002 -> Phone PH.hc003 (Hicom standard) PF0_2 | PS.base.tb2 | Phone line -106 | PS.base.b3 -> WS.002.2a in room 002 -> Phone PH.hc003 (Hicom standard)
PF0_2 |PS.base.tb3 |Phone line -108 |- PF0_2 | PS.base.tb3 | Phone line -108 | -
PF0_2 |PS.base.tb4 |Phone line -109 |- PF0_2 | PS.base.tb4 | Phone line -109 | -
PF0_2 |PS.base.tb5 |Phone line -121 |- PF0_2 | PS.base.tb5 | Phone line -121 | -
PF0_2 |PS.base.tb6 |Phone line -122 |- PF0_2 | PS.base.tb6 | Phone line -122 | -
(12 rows) (12 rows)
QUERY: insert into PField values ('PF1_1', 'should fail due to unique index'); --
-- Finally we want errors
--
insert into PField values ('PF1_1', 'should fail due to unique index');
ERROR: Cannot insert a duplicate key into unique index pfield_name ERROR: Cannot insert a duplicate key into unique index pfield_name
QUERY: update PSlot set backlink = 'WS.not.there' where slotname = 'PS.base.a1'; update PSlot set backlink = 'WS.not.there' where slotname = 'PS.base.a1';
ERROR: WS.not.there does not exists ERROR: WS.not.there does not exists
QUERY: update PSlot set backlink = 'XX.illegal' where slotname = 'PS.base.a1'; update PSlot set backlink = 'XX.illegal' where slotname = 'PS.base.a1';
ERROR: illegal backlink beginning with XX ERROR: illegal backlink beginning with XX
QUERY: update PSlot set slotlink = 'PS.not.there' where slotname = 'PS.base.a1'; update PSlot set slotlink = 'PS.not.there' where slotname = 'PS.base.a1';
ERROR: PS.not.there does not exists ERROR: PS.not.there does not exists
QUERY: update PSlot set slotlink = 'XX.illegal' where slotname = 'PS.base.a1'; update PSlot set slotlink = 'XX.illegal' where slotname = 'PS.base.a1';
ERROR: illegal slotlink beginning with XX ERROR: illegal slotlink beginning with XX
QUERY: insert into HSlot values ('HS', 'base.hub1', 1, ''); insert into HSlot values ('HS', 'base.hub1', 1, '');
ERROR: Cannot insert a duplicate key into unique index hslot_name ERROR: Cannot insert a duplicate key into unique index hslot_name
QUERY: insert into HSlot values ('HS', 'base.hub1', 20, ''); insert into HSlot values ('HS', 'base.hub1', 20, '');
ERROR: no manual manipulation of HSlot ERROR: no manual manipulation of HSlot
QUERY: delete from HSlot; delete from HSlot;
ERROR: no manual manipulation of HSlot ERROR: no manual manipulation of HSlot
QUERY: insert into IFace values ('IF', 'notthere', 'eth0', ''); insert into IFace values ('IF', 'notthere', 'eth0', '');
ERROR: system "notthere" does not exist ERROR: system "notthere" does not exist
QUERY: insert into IFace values ('IF', 'orion', 'ethernet_interface_name_too_long', ''); insert into IFace values ('IF', 'orion', 'ethernet_interface_name_too_long', '');
ERROR: IFace slotname "IF.orion.ethernet_interface_name_too_long" too long (20 char max) ERROR: IFace slotname "IF.orion.ethernet_interface_name_too_long" too long (20 char max)
This source diff could not be displayed because it is too large. You can view the blob instead.
QUERY: BEGIN; --
QUERY: DECLARE foo13 CURSOR FOR -- PORTALS_P2
--
-- EXTEND INDEX onek2_u1_prtl WHERE onek2.unique1 <= 60;
BEGIN;
DECLARE foo13 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 50; SELECT * FROM onek WHERE unique1 = 50;
QUERY: DECLARE foo14 CURSOR FOR DECLARE foo14 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 51; SELECT * FROM onek WHERE unique1 = 51;
QUERY: DECLARE foo15 CURSOR FOR DECLARE foo15 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 52; SELECT * FROM onek WHERE unique1 = 52;
QUERY: DECLARE foo16 CURSOR FOR DECLARE foo16 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 53; SELECT * FROM onek WHERE unique1 = 53;
QUERY: DECLARE foo17 CURSOR FOR DECLARE foo17 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 54; SELECT * FROM onek WHERE unique1 = 54;
QUERY: DECLARE foo18 CURSOR FOR DECLARE foo18 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 55; SELECT * FROM onek WHERE unique1 = 55;
QUERY: DECLARE foo19 CURSOR FOR DECLARE foo19 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 56; SELECT * FROM onek WHERE unique1 = 56;
QUERY: DECLARE foo20 CURSOR FOR DECLARE foo20 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 57; SELECT * FROM onek WHERE unique1 = 57;
QUERY: DECLARE foo21 CURSOR FOR DECLARE foo21 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 58; SELECT * FROM onek WHERE unique1 = 58;
QUERY: DECLARE foo22 CURSOR FOR DECLARE foo22 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 59; SELECT * FROM onek WHERE unique1 = 59;
QUERY: DECLARE foo23 CURSOR FOR DECLARE foo23 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 60; SELECT * FROM onek WHERE unique1 = 60;
QUERY: DECLARE foo24 CURSOR FOR DECLARE foo24 CURSOR FOR
SELECT * FROM onek2 WHERE unique1 = 50; SELECT * FROM onek2 WHERE unique1 = 50;
QUERY: DECLARE foo25 CURSOR FOR DECLARE foo25 CURSOR FOR
SELECT * FROM onek2 WHERE unique1 = 60; SELECT * FROM onek2 WHERE unique1 = 60;
QUERY: FETCH all in foo13; FETCH all in foo13;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
50| 253| 0| 2| 0| 10| 0| 50| 50| 50| 50| 0| 1|YBAAAA |TJAAAA |HHHHxx 50 | 253 | 0 | 2 | 0 | 10 | 0 | 50 | 50 | 50 | 50 | 0 | 1 | YBAAAA | TJAAAA | HHHHxx
(1 row) (1 row)
QUERY: FETCH all in foo14; FETCH all in foo14;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
51| 76| 1| 3| 1| 11| 1| 51| 51| 51| 51| 2| 3|ZBAAAA |YCAAAA |AAAAxx 51 | 76 | 1 | 3 | 1 | 11 | 1 | 51 | 51 | 51 | 51 | 2 | 3 | ZBAAAA | YCAAAA | AAAAxx
(1 row) (1 row)
QUERY: FETCH all in foo15; FETCH all in foo15;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
52| 985| 0| 0| 2| 12| 2| 52| 52| 52| 52| 4| 5|ACAAAA |XLBAAA |HHHHxx 52 | 985 | 0 | 0 | 2 | 12 | 2 | 52 | 52 | 52 | 52 | 4 | 5 | ACAAAA | XLBAAA | HHHHxx
(1 row) (1 row)
QUERY: FETCH all in foo16; FETCH all in foo16;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
53| 196| 1| 1| 3| 13| 3| 53| 53| 53| 53| 6| 7|BCAAAA |OHAAAA |AAAAxx 53 | 196 | 1 | 1 | 3 | 13 | 3 | 53 | 53 | 53 | 53 | 6 | 7 | BCAAAA | OHAAAA | AAAAxx
(1 row) (1 row)
QUERY: FETCH all in foo17; FETCH all in foo17;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
54| 356| 0| 2| 4| 14| 4| 54| 54| 54| 54| 8| 9|CCAAAA |SNAAAA |AAAAxx 54 | 356 | 0 | 2 | 4 | 14 | 4 | 54 | 54 | 54 | 54 | 8 | 9 | CCAAAA | SNAAAA | AAAAxx
(1 row) (1 row)
QUERY: FETCH all in foo18; FETCH all in foo18;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
55| 627| 1| 3| 5| 15| 5| 55| 55| 55| 55| 10| 11|DCAAAA |DYAAAA |VVVVxx 55 | 627 | 1 | 3 | 5 | 15 | 5 | 55 | 55 | 55 | 55 | 10 | 11 | DCAAAA | DYAAAA | VVVVxx
(1 row) (1 row)
QUERY: FETCH all in foo19; FETCH all in foo19;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
56| 54| 0| 0| 6| 16| 6| 56| 56| 56| 56| 12| 13|ECAAAA |CCAAAA |OOOOxx 56 | 54 | 0 | 0 | 6 | 16 | 6 | 56 | 56 | 56 | 56 | 12 | 13 | ECAAAA | CCAAAA | OOOOxx
(1 row) (1 row)
QUERY: FETCH all in foo20; FETCH all in foo20;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
57| 942| 1| 1| 7| 17| 7| 57| 57| 57| 57| 14| 15|FCAAAA |GKBAAA |OOOOxx 57 | 942 | 1 | 1 | 7 | 17 | 7 | 57 | 57 | 57 | 57 | 14 | 15 | FCAAAA | GKBAAA | OOOOxx
(1 row) (1 row)
QUERY: FETCH all in foo21; FETCH all in foo21;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
58| 114| 0| 2| 8| 18| 8| 58| 58| 58| 58| 16| 17|GCAAAA |KEAAAA |OOOOxx 58 | 114 | 0 | 2 | 8 | 18 | 8 | 58 | 58 | 58 | 58 | 16 | 17 | GCAAAA | KEAAAA | OOOOxx
(1 row) (1 row)
QUERY: FETCH all in foo22; FETCH all in foo22;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
59| 593| 1| 3| 9| 19| 9| 59| 59| 59| 59| 18| 19|HCAAAA |VWAAAA |HHHHxx 59 | 593 | 1 | 3 | 9 | 19 | 9 | 59 | 59 | 59 | 59 | 18 | 19 | HCAAAA | VWAAAA | HHHHxx
(1 row) (1 row)
QUERY: FETCH all in foo23; FETCH all in foo23;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
60| 483| 0| 0| 0| 0| 0| 60| 60| 60| 60| 0| 1|ICAAAA |PSAAAA |VVVVxx 60 | 483 | 0 | 0 | 0 | 0 | 0 | 60 | 60 | 60 | 60 | 0 | 1 | ICAAAA | PSAAAA | VVVVxx
(1 row) (1 row)
QUERY: FETCH all in foo24; FETCH all in foo24;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
50| 253| 0| 2| 0| 10| 0| 50| 50| 50| 50| 0| 1|YBAAAA |TJAAAA |HHHHxx 50 | 253 | 0 | 2 | 0 | 10 | 0 | 50 | 50 | 50 | 50 | 0 | 1 | YBAAAA | TJAAAA | HHHHxx
(1 row) (1 row)
QUERY: FETCH all in foo25; FETCH all in foo25;
unique1|unique2|two|four|ten|twenty|hundred|thousand|twothousand|fivethous|tenthous|odd|even|stringu1|stringu2|string4 unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4
-------+-------+---+----+---+------+-------+--------+-----------+---------+--------+---+----+--------+--------+------- ---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+---------
60| 483| 0| 0| 0| 0| 0| 60| 60| 60| 60| 0| 1|ICAAAA |PSAAAA |VVVVxx 60 | 483 | 0 | 0 | 0 | 0 | 0 | 60 | 60 | 60 | 60 | 0 | 1 | ICAAAA | PSAAAA | VVVVxx
(1 row) (1 row)
QUERY: CLOSE foo13; CLOSE foo13;
QUERY: CLOSE foo14; CLOSE foo14;
QUERY: CLOSE foo15; CLOSE foo15;
QUERY: CLOSE foo16; CLOSE foo16;
QUERY: CLOSE foo17; CLOSE foo17;
QUERY: CLOSE foo18; CLOSE foo18;
QUERY: CLOSE foo19; CLOSE foo19;
QUERY: CLOSE foo20; CLOSE foo20;
QUERY: CLOSE foo21; CLOSE foo21;
QUERY: CLOSE foo22; CLOSE foo22;
QUERY: CLOSE foo23; CLOSE foo23;
QUERY: CLOSE foo24; CLOSE foo24;
QUERY: CLOSE foo25; CLOSE foo25;
QUERY: END; END;
QUERY: create table rtest_t1 (a int4, b int4); --
QUERY: create table rtest_t2 (a int4, b int4); -- RULES
QUERY: create table rtest_t3 (a int4, b int4); -- From Jan's original setup_ruletest.sql and run_ruletest.sql
QUERY: create view rtest_v1 as select * from rtest_t1; -- - thomas 1998-09-13
QUERY: create rule rtest_v1_ins as on insert to rtest_v1 do instead --
--
-- 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); insert into rtest_t1 values (new.a, new.b);
QUERY: create rule rtest_v1_upd as on update to rtest_v1 do instead create rule rtest_v1_upd as on update to rtest_v1 do instead
update rtest_t1 set a = new.a, b = new.b update rtest_t1 set a = new.a, b = new.b
where a = old.a; where a = old.a;
QUERY: create rule rtest_v1_del as on delete to rtest_v1 do instead create rule rtest_v1_del as on delete to rtest_v1 do instead
delete from rtest_t1 where a = old.a; 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); -- Tables and rules for the constraint update/delete test
QUERY: create table rtest_person (pname text, pdesc text); --
QUERY: create table rtest_admin (pname text, sysname text); -- Note:
QUERY: create rule rtest_sys_upd as on update to rtest_system do ( -- Now that we have multiple action rule support, we check
update rtest_interface set sysname = new.sysname -- both possible syntaxes to define them (The last action
-- can but must not have a semicolon at the end).
--
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_upd as on update to rtest_system do (
update rtest_interface set sysname = new.sysname
where sysname = old.sysname; where sysname = old.sysname;
update rtest_admin set sysname = new.sysname update rtest_admin set sysname = new.sysname
where sysname = old.sysname where sysname = old.sysname
); );
QUERY: create rule rtest_sys_del as on delete to rtest_system do ( create rule rtest_sys_del as on delete to rtest_system do (
delete from rtest_interface where sysname = old.sysname; delete from rtest_interface where sysname = old.sysname;
delete from rtest_admin 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 create rule rtest_pers_upd as on update to rtest_person do
update rtest_admin set pname = new.pname where pname = old.pname; update rtest_admin set pname = new.pname where pname = old.pname;
QUERY: create rule rtest_pers_del as on delete to rtest_person do create rule rtest_pers_del as on delete to rtest_person do
delete from rtest_admin where pname = old.pname; 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); -- Tables and rules for the logging test
QUERY: create table rtest_empmass (ename char(20), salary money); --
QUERY: create rule rtest_emp_ins as on insert to rtest_emp do 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, insert into rtest_emplog values (new.ename, current_user,
'hired', new.salary, '0.00'); 'hired', new.salary, '0.00');
QUERY: create rule rtest_emp_upd as on update to rtest_emp where new.salary != old.salary do 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, insert into rtest_emplog values (new.ename, current_user,
'honored', new.salary, old.salary); 'honored', new.salary, old.salary);
QUERY: create rule rtest_emp_del as on delete to rtest_emp do create rule rtest_emp_del as on delete to rtest_emp do
insert into rtest_emplog values (old.ename, current_user, insert into rtest_emplog values (old.ename, current_user,
'fired', '0.00', old.salary); 'fired', '0.00', old.salary);
QUERY: create table rtest_t4 (a int4, b text); --
QUERY: create table rtest_t5 (a int4, b text); -- Tables and rules for the multiple cascaded qualified instead
QUERY: create table rtest_t6 (a int4, b text); -- rule test
QUERY: create table rtest_t7 (a int4, b text); --
QUERY: create table rtest_t8 (a int4, b text); create table rtest_t4 (a int4, b text);
QUERY: create table rtest_t9 (a int4, b text); create table rtest_t5 (a int4, b text);
QUERY: create rule rtest_t4_ins1 as on insert to rtest_t4 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 where new.a >= 10 and new.a < 20 do instead
insert into rtest_t5 values (new.a, new.b); insert into rtest_t5 values (new.a, new.b);
QUERY: create rule rtest_t4_ins2 as on insert to rtest_t4 create rule rtest_t4_ins2 as on insert to rtest_t4
where new.a >= 20 and new.a < 30 do where new.a >= 20 and new.a < 30 do
insert into rtest_t6 values (new.a, new.b); insert into rtest_t6 values (new.a, new.b);
QUERY: create rule rtest_t5_ins as on insert to rtest_t5 create rule rtest_t5_ins as on insert to rtest_t5
where new.a > 15 do where new.a > 15 do
insert into rtest_t7 values (new.a, new.b); insert into rtest_t7 values (new.a, new.b);
QUERY: create rule rtest_t6_ins as on insert to rtest_t6 create rule rtest_t6_ins as on insert to rtest_t6
where new.a > 25 do instead where new.a > 25 do instead
insert into rtest_t8 values (new.a, new.b); 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); -- Tables and rules for the rule fire order test
QUERY: create sequence rtest_seq; --
QUERY: create rule rtest_order_r3 as on insert to rtest_order1 do instead 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'), insert into rtest_order2 values (new.a, nextval('rtest_seq'),
'rule 3 - this should run 3rd or 4th'); 'rule 3 - this should run 3rd or 4th');
QUERY: create rule rtest_order_r4 as on insert to rtest_order1 create rule rtest_order_r4 as on insert to rtest_order1
where a < 100 do instead where a < 100 do instead
insert into rtest_order2 values (new.a, nextval('rtest_seq'), insert into rtest_order2 values (new.a, nextval('rtest_seq'),
'rule 4 - this should run 2nd'); 'rule 4 - this should run 2nd');
QUERY: create rule rtest_order_r2 as on insert to rtest_order1 do create rule rtest_order_r2 as on insert to rtest_order1 do
insert into rtest_order2 values (new.a, nextval('rtest_seq'), insert into rtest_order2 values (new.a, nextval('rtest_seq'),
'rule 2 - this should run 1st'); 'rule 2 - this should run 1st');
QUERY: create rule rtest_order_r1 as on insert to rtest_order1 do instead create rule rtest_order_r1 as on insert to rtest_order1 do instead
insert into rtest_order2 values (new.a, nextval('rtest_seq'), insert into rtest_order2 values (new.a, nextval('rtest_seq'),
'rule 1 - this should run 3rd or 4th'); '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); -- Tables and rules for the instead nothing test
QUERY: create table rtest_nothn3 (a int4, b text); --
QUERY: create table rtest_nothn4 (a int4, b text); create table rtest_nothn1 (a int4, b text);
QUERY: create rule rtest_nothn_r1 as on insert to rtest_nothn1 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); where new.a >= 10 and new.a < 20 do instead (select 1);
QUERY: create rule rtest_nothn_r2 as on insert to rtest_nothn1 create rule rtest_nothn_r2 as on insert to rtest_nothn1
where new.a >= 30 and new.a < 40 do instead nothing; where new.a >= 30 and new.a < 40 do instead nothing;
QUERY: create rule rtest_nothn_r3 as on insert to rtest_nothn2 create rule rtest_nothn_r3 as on insert to rtest_nothn2
where new.a >= 100 do instead where new.a >= 100 do instead
insert into rtest_nothn3 values (new.a, new.b); insert into rtest_nothn3 values (new.a, new.b);
QUERY: create rule rtest_nothn_r4 as on insert to rtest_nothn2 create rule rtest_nothn_r4 as on insert to rtest_nothn2
do instead nothing; do instead nothing;
QUERY: insert into rtest_t2 values (1, 21); --
QUERY: insert into rtest_t2 values (2, 22); -- Tests on a view that is select * of a table
QUERY: insert into rtest_t2 values (3, 23); -- and has insert/update/delete instead rules to
QUERY: insert into rtest_t3 values (1, 31); -- behave close like the real table.
QUERY: insert into rtest_t3 values (2, 32); --
QUERY: insert into rtest_t3 values (3, 33); --
QUERY: insert into rtest_t3 values (4, 34); -- We need test date later
QUERY: insert into rtest_t3 values (5, 35); --
QUERY: insert into rtest_v1 values (1, 11); insert into rtest_t2 values (1, 21);
QUERY: insert into rtest_v1 values (2, 12); insert into rtest_t2 values (2, 22);
QUERY: select * from rtest_v1; insert into rtest_t2 values (3, 23);
a| b insert into rtest_t3 values (1, 31);
-+-- insert into rtest_t3 values (2, 32);
1|11 insert into rtest_t3 values (3, 33);
2|12 insert into rtest_t3 values (4, 34);
insert into rtest_t3 values (5, 35);
-- insert values
insert into rtest_v1 values (1, 11);
insert into rtest_v1 values (2, 12);
select * from rtest_v1;
a | b
---+----
1 | 11
2 | 12
(2 rows) (2 rows)
QUERY: delete from rtest_v1 where a = 1; -- delete with constant expression
QUERY: select * from rtest_v1; delete from rtest_v1 where a = 1;
a| b select * from rtest_v1;
-+-- a | b
2|12 ---+----
2 | 12
(1 row) (1 row)
QUERY: insert into rtest_v1 values (1, 11); insert into rtest_v1 values (1, 11);
QUERY: delete from rtest_v1 where b = 12; delete from rtest_v1 where b = 12;
QUERY: select * from rtest_v1; select * from rtest_v1;
a| b a | b
-+-- ---+----
1|11 1 | 11
(1 row) (1 row)
QUERY: insert into rtest_v1 values (2, 12); insert into rtest_v1 values (2, 12);
QUERY: insert into rtest_v1 values (2, 13); insert into rtest_v1 values (2, 13);
QUERY: select * from rtest_v1; select * from rtest_v1;
a| b a | b
-+-- ---+----
1|11 1 | 11
2|12 2 | 12
2|13 2 | 13
(3 rows) (3 rows)
** Remember the delete rule on rtest_v1: It says ** Remember the delete rule on rtest_v1: It says
** DO INSTEAD DELETE FROM rtest_t1 WHERE a = old.a ** DO INSTEAD DELETE FROM rtest_t1 WHERE a = old.a
** So this time both rows with a = 2 must get deleted ** So this time both rows with a = 2 must get deleted
QUERY: delete from rtest_v1 where b = 12; \p
QUERY: select * from rtest_v1; ** Remember the delete rule on rtest_v1: It says
a| b ** DO INSTEAD DELETE FROM rtest_t1 WHERE a = old.a
-+-- ** So this time both rows with a = 2 must get deleted
1|11 \r
delete from rtest_v1 where b = 12;
select * from rtest_v1;
a | b
---+----
1 | 11
(1 row) (1 row)
QUERY: delete from rtest_v1; delete from rtest_v1;
QUERY: insert into rtest_v1 select * from rtest_t2; -- insert select
QUERY: select * from rtest_v1; insert into rtest_v1 select * from rtest_t2;
a| b select * from rtest_v1;
-+-- a | b
1|21 ---+----
2|22 1 | 21
3|23 2 | 22
3 | 23
(3 rows) (3 rows)
QUERY: delete from rtest_v1; delete from rtest_v1;
QUERY: insert into rtest_v1 (b, a) select b, a from rtest_t2; -- same with swapped targetlist
QUERY: select * from rtest_v1; insert into rtest_v1 (b, a) select b, a from rtest_t2;
a| b select * from rtest_v1;
-+-- a | b
1|21 ---+----
2|22 1 | 21
3|23 2 | 22
3 | 23
(3 rows) (3 rows)
QUERY: insert into rtest_v1 (a) select a from rtest_t3; -- now with only one target attribute
QUERY: select * from rtest_v1; insert into rtest_v1 (a) select a from rtest_t3;
a| b select * from rtest_v1;
-+-- a | b
1|21 ---+----
2|22 1 | 21
3|23 2 | 22
1| 3 | 23
2| 1 |
3| 2 |
4| 3 |
5| 4 |
5 |
(8 rows) (8 rows)
QUERY: select * from rtest_v1 where b isnull; select * from rtest_v1 where b isnull;
a|b a | b
-+- ---+---
1| 1 |
2| 2 |
3| 3 |
4| 4 |
5| 5 |
(5 rows) (5 rows)
QUERY: update rtest_t1 set a = a + 10 where b isnull; -- let attribute a differ (must be done on rtest_t1 - see above)
QUERY: delete from rtest_v1 where b isnull; update rtest_t1 set a = a + 10 where b isnull;
QUERY: select * from rtest_v1; delete from rtest_v1 where b isnull;
a| b select * from rtest_v1;
-+-- a | b
1|21 ---+----
2|22 1 | 21
3|23 2 | 22
3 | 23
(3 rows) (3 rows)
QUERY: update rtest_v1 set b = 42 where a = 2; -- now updates with constant expression
QUERY: select * from rtest_v1; update rtest_v1 set b = 42 where a = 2;
a| b select * from rtest_v1;
-+-- a | b
1|21 ---+----
3|23 1 | 21
2|42 3 | 23
2 | 42
(3 rows) (3 rows)
QUERY: update rtest_v1 set b = 99 where b = 42; update rtest_v1 set b = 99 where b = 42;
QUERY: select * from rtest_v1; select * from rtest_v1;
a| b a | b
-+-- ---+----
1|21 1 | 21
3|23 3 | 23
2|99 2 | 99
(3 rows) (3 rows)
QUERY: update rtest_v1 set b = 88 where b < 50; update rtest_v1 set b = 88 where b < 50;
QUERY: select * from rtest_v1; select * from rtest_v1;
a| b a | b
-+-- ---+----
2|99 2 | 99
1|88 1 | 88
3|88 3 | 88
(3 rows) (3 rows)
QUERY: delete from rtest_v1; delete from rtest_v1;
QUERY: insert into rtest_v1 select rtest_t2.a, rtest_t3.b where rtest_t2.a = rtest_t3.a; insert into rtest_v1 select rtest_t2.a, rtest_t3.b where rtest_t2.a = rtest_t3.a;
QUERY: select * from rtest_v1; select * from rtest_v1;
a| b a | b
-+-- ---+----
1|31 1 | 31
2|32 2 | 32
3|33 3 | 33
(3 rows) (3 rows)
QUERY: update rtest_v1 set b = rtest_t2.b where a = rtest_t2.a; -- updates in a mergejoin
QUERY: select * from rtest_v1; update rtest_v1 set b = rtest_t2.b where a = rtest_t2.a;
a| b select * from rtest_v1;
-+-- a | b
1|21 ---+----
2|22 1 | 21
3|23 2 | 22
3 | 23
(3 rows) (3 rows)
QUERY: insert into rtest_v1 select * from rtest_t3; insert into rtest_v1 select * from rtest_t3;
QUERY: select * from rtest_v1; select * from rtest_v1;
a| b a | b
-+-- ---+----
1|21 1 | 21
2|22 2 | 22
3|23 3 | 23
1|31 1 | 31
2|32 2 | 32
3|33 3 | 33
4|34 4 | 34
5|35 5 | 35
(8 rows) (8 rows)
QUERY: update rtest_t1 set a = a + 10 where b > 30; update rtest_t1 set a = a + 10 where b > 30;
QUERY: select * from rtest_v1; select * from rtest_v1;
a| b a | b
--+-- ----+----
1|21 1 | 21
2|22 2 | 22
3|23 3 | 23
11|31 11 | 31
12|32 12 | 32
13|33 13 | 33
14|34 14 | 34
15|35 15 | 35
(8 rows) (8 rows)
QUERY: update rtest_v1 set a = rtest_t3.a + 20 where b = rtest_t3.b; update rtest_v1 set a = rtest_t3.a + 20 where b = rtest_t3.b;
QUERY: select * from rtest_v1; select * from rtest_v1;
a| b a | b
--+-- ----+----
1|21 1 | 21
2|22 2 | 22
3|23 3 | 23
21|31 21 | 31
22|32 22 | 32
23|33 23 | 33
24|34 24 | 34
25|35 25 | 35
(8 rows) (8 rows)
QUERY: insert into rtest_system values ('orion', 'Linux Jan Wieck'); --
QUERY: insert into rtest_system values ('notjw', 'WinNT Jan Wieck (notebook)'); -- Test for constraint updates/deletes
QUERY: insert into rtest_system values ('neptun', 'Fileserver'); --
QUERY: insert into rtest_interface values ('orion', 'eth0'); insert into rtest_system values ('orion', 'Linux Jan Wieck');
QUERY: insert into rtest_interface values ('orion', 'eth1'); insert into rtest_system values ('notjw', 'WinNT Jan Wieck (notebook)');
QUERY: insert into rtest_interface values ('notjw', 'eth0'); insert into rtest_system values ('neptun', 'Fileserver');
QUERY: insert into rtest_interface values ('neptun', 'eth0'); insert into rtest_interface values ('orion', 'eth0');
QUERY: insert into rtest_person values ('jw', 'Jan Wieck'); insert into rtest_interface values ('orion', 'eth1');
QUERY: insert into rtest_person values ('bm', 'Bruce Momjian'); insert into rtest_interface values ('notjw', 'eth0');
QUERY: insert into rtest_admin values ('jw', 'orion'); insert into rtest_interface values ('neptun', 'eth0');
QUERY: insert into rtest_admin values ('jw', 'notjw'); insert into rtest_person values ('jw', 'Jan Wieck');
QUERY: insert into rtest_admin values ('bm', 'neptun'); insert into rtest_person values ('bm', 'Bruce Momjian');
QUERY: update rtest_system set sysname = 'pluto' where sysname = 'neptun'; insert into rtest_admin values ('jw', 'orion');
QUERY: select * from rtest_interface; insert into rtest_admin values ('jw', 'notjw');
sysname|ifname insert into rtest_admin values ('bm', 'neptun');
-------+------ update rtest_system set sysname = 'pluto' where sysname = 'neptun';
orion |eth0 select * from rtest_interface;
orion |eth1 sysname | ifname
notjw |eth0 ---------+--------
pluto |eth0 orion | eth0
orion | eth1
notjw | eth0
pluto | eth0
(4 rows) (4 rows)
QUERY: select * from rtest_admin; select * from rtest_admin;
pname|sysname pname | sysname
-----+------- -------+---------
jw |orion jw | orion
jw |notjw jw | notjw
bm |pluto bm | pluto
(3 rows) (3 rows)
QUERY: update rtest_person set pname = 'jwieck' where pdesc = 'Jan Wieck'; update rtest_person set pname = 'jwieck' where pdesc = 'Jan Wieck';
QUERY: select * from rtest_admin order by pname, sysname; -- Note: use ORDER BY here to ensure consistent output across all systems.
pname |sysname -- The above UPDATE affects two rows with equal keys, so they could be
------+------- -- updated in either order depending on the whim of the local qsort().
bm |pluto select * from rtest_admin order by pname, sysname;
jwieck|notjw pname | sysname
jwieck|orion --------+---------
bm | pluto
jwieck | notjw
jwieck | orion
(3 rows) (3 rows)
QUERY: delete from rtest_system where sysname = 'orion'; delete from rtest_system where sysname = 'orion';
QUERY: select * from rtest_interface; select * from rtest_interface;
sysname|ifname sysname | ifname
-------+------ ---------+--------
notjw |eth0 notjw | eth0
pluto |eth0 pluto | eth0
(2 rows) (2 rows)
QUERY: select * from rtest_admin; select * from rtest_admin;
pname |sysname pname | sysname
------+------- --------+---------
bm |pluto bm | pluto
jwieck|notjw jwieck | notjw
(2 rows) (2 rows)
QUERY: insert into rtest_emp values ('wiech', '5000.00'); --
QUERY: insert into rtest_emp values ('gates', '80000.00'); -- Rule qualification test
QUERY: update rtest_emp set ename = 'wiecx' where ename = 'wiech'; --
QUERY: update rtest_emp set ename = 'wieck', salary = '6000.00' where ename = 'wiecx'; insert into rtest_emp values ('wiech', '5000.00');
QUERY: update rtest_emp set salary = '7000.00' where ename = 'wieck'; insert into rtest_emp values ('gates', '80000.00');
QUERY: delete from rtest_emp where ename = 'gates'; update rtest_emp set ename = 'wiecx' where ename = 'wiech';
QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal; update rtest_emp set ename = 'wieck', salary = '6000.00' where ename = 'wiecx';
ename |matches user|action |newsal |oldsal update rtest_emp set salary = '7000.00' where ename = 'wieck';
--------------------+------------+----------+----------+---------- delete from rtest_emp where ename = 'gates';
gates |t |fired |$0.00 |$80,000.00 select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal;
gates |t |hired |$80,000.00|$0.00 ename | matches user | action | newsal | oldsal
wiech |t |hired |$5,000.00 |$0.00 ----------------------+--------------+------------+------------+------------
wieck |t |honored |$6,000.00 |$5,000.00 gates | t | fired | $0.00 | $80,000.00
wieck |t |honored |$7,000.00 |$6,000.00 gates | t | hired | $80,000.00 | $0.00
wiech | t | hired | $5,000.00 | $0.00
wieck | t | honored | $6,000.00 | $5,000.00
wieck | t | honored | $7,000.00 | $6,000.00
(5 rows) (5 rows)
QUERY: insert into rtest_empmass values ('meyer', '4000.00'); insert into rtest_empmass values ('meyer', '4000.00');
QUERY: insert into rtest_empmass values ('maier', '5000.00'); insert into rtest_empmass values ('maier', '5000.00');
QUERY: insert into rtest_empmass values ('mayr', '6000.00'); insert into rtest_empmass values ('mayr', '6000.00');
QUERY: insert into rtest_emp select * from rtest_empmass; insert into rtest_emp select * from rtest_empmass;
QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal; select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal;
ename |matches user|action |newsal |oldsal ename | matches user | action | newsal | oldsal
--------------------+------------+----------+----------+---------- ----------------------+--------------+------------+------------+------------
gates |t |fired |$0.00 |$80,000.00 gates | t | fired | $0.00 | $80,000.00
gates |t |hired |$80,000.00|$0.00 gates | t | hired | $80,000.00 | $0.00
maier |t |hired |$5,000.00 |$0.00 maier | t | hired | $5,000.00 | $0.00
mayr |t |hired |$6,000.00 |$0.00 mayr | t | hired | $6,000.00 | $0.00
meyer |t |hired |$4,000.00 |$0.00 meyer | t | hired | $4,000.00 | $0.00
wiech |t |hired |$5,000.00 |$0.00 wiech | t | hired | $5,000.00 | $0.00
wieck |t |honored |$6,000.00 |$5,000.00 wieck | t | honored | $6,000.00 | $5,000.00
wieck |t |honored |$7,000.00 |$6,000.00 wieck | t | honored | $7,000.00 | $6,000.00
(8 rows) (8 rows)
QUERY: update rtest_empmass set salary = salary + '1000.00'; update rtest_empmass set salary = salary + '1000.00';
QUERY: update rtest_emp set salary = rtest_empmass.salary where ename = rtest_empmass.ename; 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 order by ename, action, newsal; select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal;
ename |matches user|action |newsal |oldsal ename | matches user | action | newsal | oldsal
--------------------+------------+----------+----------+---------- ----------------------+--------------+------------+------------+------------
gates |t |fired |$0.00 |$80,000.00 gates | t | fired | $0.00 | $80,000.00
gates |t |hired |$80,000.00|$0.00 gates | t | hired | $80,000.00 | $0.00
maier |t |hired |$5,000.00 |$0.00 maier | t | hired | $5,000.00 | $0.00
maier |t |honored |$6,000.00 |$5,000.00 maier | t | honored | $6,000.00 | $5,000.00
mayr |t |hired |$6,000.00 |$0.00 mayr | t | hired | $6,000.00 | $0.00
mayr |t |honored |$7,000.00 |$6,000.00 mayr | t | honored | $7,000.00 | $6,000.00
meyer |t |hired |$4,000.00 |$0.00 meyer | t | hired | $4,000.00 | $0.00
meyer |t |honored |$5,000.00 |$4,000.00 meyer | t | honored | $5,000.00 | $4,000.00
wiech |t |hired |$5,000.00 |$0.00 wiech | t | hired | $5,000.00 | $0.00
wieck |t |honored |$6,000.00 |$5,000.00 wieck | t | honored | $6,000.00 | $5,000.00
wieck |t |honored |$7,000.00 |$6,000.00 wieck | t | honored | $7,000.00 | $6,000.00
(11 rows) (11 rows)
QUERY: delete from rtest_emp where ename = rtest_empmass.ename; delete from rtest_emp where ename = rtest_empmass.ename;
QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal; select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal;
ename |matches user|action |newsal |oldsal ename | matches user | action | newsal | oldsal
--------------------+------------+----------+----------+---------- ----------------------+--------------+------------+------------+------------
gates |t |fired |$0.00 |$80,000.00 gates | t | fired | $0.00 | $80,000.00
gates |t |hired |$80,000.00|$0.00 gates | t | hired | $80,000.00 | $0.00
maier |t |fired |$0.00 |$6,000.00 maier | t | fired | $0.00 | $6,000.00
maier |t |hired |$5,000.00 |$0.00 maier | t | hired | $5,000.00 | $0.00
maier |t |honored |$6,000.00 |$5,000.00 maier | t | honored | $6,000.00 | $5,000.00
mayr |t |fired |$0.00 |$7,000.00 mayr | t | fired | $0.00 | $7,000.00
mayr |t |hired |$6,000.00 |$0.00 mayr | t | hired | $6,000.00 | $0.00
mayr |t |honored |$7,000.00 |$6,000.00 mayr | t | honored | $7,000.00 | $6,000.00
meyer |t |fired |$0.00 |$5,000.00 meyer | t | fired | $0.00 | $5,000.00
meyer |t |hired |$4,000.00 |$0.00 meyer | t | hired | $4,000.00 | $0.00
meyer |t |honored |$5,000.00 |$4,000.00 meyer | t | honored | $5,000.00 | $4,000.00
wiech |t |hired |$5,000.00 |$0.00 wiech | t | hired | $5,000.00 | $0.00
wieck |t |honored |$6,000.00 |$5,000.00 wieck | t | honored | $6,000.00 | $5,000.00
wieck |t |honored |$7,000.00 |$6,000.00 wieck | t | honored | $7,000.00 | $6,000.00
(14 rows) (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'); -- Multiple cascaded qualified instead rule test
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'); insert into rtest_t4 values (1, 'Record should go to rtest_t4');
QUERY: insert into rtest_t4 values (19, 'Record should go to rtest_t5 and t7'); insert into rtest_t4 values (2, 'Record should go to rtest_t4');
QUERY: insert into rtest_t4 values (20, 'Record should go to rtest_t4 and t6'); insert into rtest_t4 values (10, 'Record should go to rtest_t5');
QUERY: insert into rtest_t4 values (26, 'Record should go to rtest_t4 and t8'); insert into rtest_t4 values (15, 'Record should go to rtest_t5');
QUERY: insert into rtest_t4 values (28, 'Record should go to rtest_t4 and t8'); insert into rtest_t4 values (19, 'Record should go to rtest_t5 and t7');
QUERY: insert into rtest_t4 values (30, 'Record should go to rtest_t4'); insert into rtest_t4 values (20, 'Record should go to rtest_t4 and t6');
QUERY: insert into rtest_t4 values (40, 'Record should go to rtest_t4'); insert into rtest_t4 values (26, 'Record should go to rtest_t4 and t8');
QUERY: select * from rtest_t4; insert into rtest_t4 values (28, 'Record should go to rtest_t4 and t8');
a|b insert into rtest_t4 values (30, 'Record should go to rtest_t4');
--+----------------------------------- insert into rtest_t4 values (40, 'Record should go to rtest_t4');
1|Record should go to rtest_t4 select * from rtest_t4;
2|Record should go to rtest_t4 a | b
20|Record should go to rtest_t4 and t6 ----+-------------------------------------
26|Record should go to rtest_t4 and t8 1 | Record should go to rtest_t4
28|Record should go to rtest_t4 and t8 2 | Record should go to rtest_t4
30|Record should go to rtest_t4 20 | Record should go to rtest_t4 and t6
40|Record should go to rtest_t4 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) (7 rows)
QUERY: select * from rtest_t5; select * from rtest_t5;
a|b a | b
--+----------------------------------- ----+-------------------------------------
10|Record should go to rtest_t5 10 | Record should go to rtest_t5
15|Record should go to rtest_t5 15 | Record should go to rtest_t5
19|Record should go to rtest_t5 and t7 19 | Record should go to rtest_t5 and t7
(3 rows) (3 rows)
QUERY: select * from rtest_t6; select * from rtest_t6;
a|b a | b
--+----------------------------------- ----+-------------------------------------
20|Record should go to rtest_t4 and t6 20 | Record should go to rtest_t4 and t6
(1 row) (1 row)
QUERY: select * from rtest_t7; select * from rtest_t7;
a|b a | b
--+----------------------------------- ----+-------------------------------------
19|Record should go to rtest_t5 and t7 19 | Record should go to rtest_t5 and t7
(1 row) (1 row)
QUERY: select * from rtest_t8; select * from rtest_t8;
a|b a | b
--+----------------------------------- ----+-------------------------------------
26|Record should go to rtest_t4 and t8 26 | Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8 28 | Record should go to rtest_t4 and t8
(2 rows) (2 rows)
QUERY: delete from rtest_t4; delete from rtest_t4;
QUERY: delete from rtest_t5; delete from rtest_t5;
QUERY: delete from rtest_t6; delete from rtest_t6;
QUERY: delete from rtest_t7; delete from rtest_t7;
QUERY: delete from rtest_t8; delete from rtest_t8;
QUERY: insert into rtest_t9 values (1, 'Record should go to rtest_t4'); 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'); 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'); 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'); 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'); 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'); 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'); 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'); 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'); 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'); insert into rtest_t9 values (40, 'Record should go to rtest_t4');
QUERY: insert into rtest_t4 select * from rtest_t9 where a < 20; insert into rtest_t4 select * from rtest_t9 where a < 20;
QUERY: select * from rtest_t4; select * from rtest_t4;
a|b a | b
-+---------------------------- ---+------------------------------
1|Record should go to rtest_t4 1 | Record should go to rtest_t4
2|Record should go to rtest_t4 2 | Record should go to rtest_t4
(2 rows) (2 rows)
QUERY: select * from rtest_t5; select * from rtest_t5;
a|b a | b
--+----------------------------------- ----+-------------------------------------
10|Record should go to rtest_t5 10 | Record should go to rtest_t5
15|Record should go to rtest_t5 15 | Record should go to rtest_t5
19|Record should go to rtest_t5 and t7 19 | Record should go to rtest_t5 and t7
(3 rows) (3 rows)
QUERY: select * from rtest_t6; select * from rtest_t6;
a|b a | b
-+- ---+---
(0 rows) (0 rows)
QUERY: select * from rtest_t7; select * from rtest_t7;
a|b a | b
--+----------------------------------- ----+-------------------------------------
19|Record should go to rtest_t5 and t7 19 | Record should go to rtest_t5 and t7
(1 row) (1 row)
QUERY: select * from rtest_t8; select * from rtest_t8;
a|b a | b
-+- ---+---
(0 rows) (0 rows)
QUERY: insert into rtest_t4 select * from rtest_t9 where b ~ 'and t8'; insert into rtest_t4 select * from rtest_t9 where b ~ 'and t8';
QUERY: select * from rtest_t4; select * from rtest_t4;
a|b a | b
--+----------------------------------- ----+-------------------------------------
1|Record should go to rtest_t4 1 | Record should go to rtest_t4
2|Record should go to rtest_t4 2 | Record should go to rtest_t4
26|Record should go to rtest_t4 and t8 26 | Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8 28 | Record should go to rtest_t4 and t8
(4 rows) (4 rows)
QUERY: select * from rtest_t5; select * from rtest_t5;
a|b a | b
--+----------------------------------- ----+-------------------------------------
10|Record should go to rtest_t5 10 | Record should go to rtest_t5
15|Record should go to rtest_t5 15 | Record should go to rtest_t5
19|Record should go to rtest_t5 and t7 19 | Record should go to rtest_t5 and t7
(3 rows) (3 rows)
QUERY: select * from rtest_t6; select * from rtest_t6;
a|b a | b
-+- ---+---
(0 rows) (0 rows)
QUERY: select * from rtest_t7; select * from rtest_t7;
a|b a | b
--+----------------------------------- ----+-------------------------------------
19|Record should go to rtest_t5 and t7 19 | Record should go to rtest_t5 and t7
(1 row) (1 row)
QUERY: select * from rtest_t8; select * from rtest_t8;
a|b a | b
--+----------------------------------- ----+-------------------------------------
26|Record should go to rtest_t4 and t8 26 | Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8 28 | Record should go to rtest_t4 and t8
(2 rows) (2 rows)
QUERY: insert into rtest_t4 select a + 1, b from rtest_t9 where a in (20, 30, 40); insert into rtest_t4 select a + 1, b from rtest_t9 where a in (20, 30, 40);
QUERY: select * from rtest_t4; select * from rtest_t4;
a|b a | b
--+----------------------------------- ----+-------------------------------------
1|Record should go to rtest_t4 1 | Record should go to rtest_t4
2|Record should go to rtest_t4 2 | Record should go to rtest_t4
26|Record should go to rtest_t4 and t8 26 | Record should go to rtest_t4 and t8
28|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 21 | Record should go to rtest_t4 and t6
31|Record should go to rtest_t4 31 | Record should go to rtest_t4
41|Record should go to rtest_t4 41 | Record should go to rtest_t4
(7 rows) (7 rows)
QUERY: select * from rtest_t5; select * from rtest_t5;
a|b a | b
--+----------------------------------- ----+-------------------------------------
10|Record should go to rtest_t5 10 | Record should go to rtest_t5
15|Record should go to rtest_t5 15 | Record should go to rtest_t5
19|Record should go to rtest_t5 and t7 19 | Record should go to rtest_t5 and t7
(3 rows) (3 rows)
QUERY: select * from rtest_t6; select * from rtest_t6;
a|b a | b
--+----------------------------------- ----+-------------------------------------
21|Record should go to rtest_t4 and t6 21 | Record should go to rtest_t4 and t6
(1 row) (1 row)
QUERY: select * from rtest_t7; select * from rtest_t7;
a|b a | b
--+----------------------------------- ----+-------------------------------------
19|Record should go to rtest_t5 and t7 19 | Record should go to rtest_t5 and t7
(1 row) (1 row)
QUERY: select * from rtest_t8; select * from rtest_t8;
a|b a | b
--+----------------------------------- ----+-------------------------------------
26|Record should go to rtest_t4 and t8 26 | Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8 28 | Record should go to rtest_t4 and t8
(2 rows) (2 rows)
QUERY: insert into rtest_order1 values (1); --
QUERY: select * from rtest_order2; -- Check that the ordering of rules fired is correct
a|b|c --
-+-+----------------------------------- insert into rtest_order1 values (1);
1|1|rule 2 - this should run 1st select * from rtest_order2;
1|2|rule 4 - this should run 2nd a | b | c
1|3|rule 3 - this should run 3rd or 4th ---+---+-------------------------------------
1|4|rule 1 - this should run 3rd or 4th 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) (4 rows)
QUERY: insert into rtest_nothn1 values (1, 'want this'); --
QUERY: insert into rtest_nothn1 values (2, 'want this'); -- Check if instead nothing w/without qualification works
QUERY: insert into rtest_nothn1 values (10, 'don''t want this'); --
QUERY: insert into rtest_nothn1 values (19, 'don''t want this'); insert into rtest_nothn1 values (1, 'want this');
QUERY: insert into rtest_nothn1 values (20, 'want this'); insert into rtest_nothn1 values (2, 'want this');
QUERY: insert into rtest_nothn1 values (29, 'want this'); insert into rtest_nothn1 values (10, 'don''t want this');
QUERY: insert into rtest_nothn1 values (30, 'don''t want this'); insert into rtest_nothn1 values (19, 'don''t want this');
QUERY: insert into rtest_nothn1 values (39, 'don''t want this'); insert into rtest_nothn1 values (20, 'want this');
QUERY: insert into rtest_nothn1 values (40, 'want this'); insert into rtest_nothn1 values (29, 'want this');
QUERY: insert into rtest_nothn1 values (50, 'want this'); insert into rtest_nothn1 values (30, 'don''t want this');
QUERY: insert into rtest_nothn1 values (60, 'want this'); insert into rtest_nothn1 values (39, 'don''t want this');
QUERY: select * from rtest_nothn1; insert into rtest_nothn1 values (40, 'want this');
a|b insert into rtest_nothn1 values (50, 'want this');
--+--------- insert into rtest_nothn1 values (60, 'want this');
1|want this select * from rtest_nothn1;
2|want this a | b
20|want this ----+-----------
29|want this 1 | want this
40|want this 2 | want this
50|want this 20 | want this
60|want this 29 | want this
40 | want this
50 | want this
60 | want this
(7 rows) (7 rows)
QUERY: insert into rtest_nothn2 values (10, 'too small'); insert into rtest_nothn2 values (10, 'too small');
QUERY: insert into rtest_nothn2 values (50, 'too small'); insert into rtest_nothn2 values (50, 'too small');
QUERY: insert into rtest_nothn2 values (100, 'OK'); insert into rtest_nothn2 values (100, 'OK');
QUERY: insert into rtest_nothn2 values (200, 'OK'); insert into rtest_nothn2 values (200, 'OK');
QUERY: select * from rtest_nothn2; select * from rtest_nothn2;
a|b a | b
-+- ---+---
(0 rows) (0 rows)
QUERY: select * from rtest_nothn3; select * from rtest_nothn3;
a|b a | b
---+-- -----+----
100|OK 100 | OK
200|OK 200 | OK
(2 rows) (2 rows)
QUERY: delete from rtest_nothn1; delete from rtest_nothn1;
QUERY: delete from rtest_nothn2; delete from rtest_nothn2;
QUERY: delete from rtest_nothn3; delete from rtest_nothn3;
QUERY: insert into rtest_nothn4 values (1, 'want this'); insert into rtest_nothn4 values (1, 'want this');
QUERY: insert into rtest_nothn4 values (2, 'want this'); insert into rtest_nothn4 values (2, 'want this');
QUERY: insert into rtest_nothn4 values (10, 'don''t want this'); insert into rtest_nothn4 values (10, 'don''t want this');
QUERY: insert into rtest_nothn4 values (19, 'don''t want this'); insert into rtest_nothn4 values (19, 'don''t want this');
QUERY: insert into rtest_nothn4 values (20, 'want this'); insert into rtest_nothn4 values (20, 'want this');
QUERY: insert into rtest_nothn4 values (29, 'want this'); insert into rtest_nothn4 values (29, 'want this');
QUERY: insert into rtest_nothn4 values (30, 'don''t want this'); insert into rtest_nothn4 values (30, 'don''t want this');
QUERY: insert into rtest_nothn4 values (39, 'don''t want this'); insert into rtest_nothn4 values (39, 'don''t want this');
QUERY: insert into rtest_nothn4 values (40, 'want this'); insert into rtest_nothn4 values (40, 'want this');
QUERY: insert into rtest_nothn4 values (50, 'want this'); insert into rtest_nothn4 values (50, 'want this');
QUERY: insert into rtest_nothn4 values (60, 'want this'); insert into rtest_nothn4 values (60, 'want this');
QUERY: insert into rtest_nothn1 select * from rtest_nothn4; insert into rtest_nothn1 select * from rtest_nothn4;
QUERY: select * from rtest_nothn1; select * from rtest_nothn1;
a|b a | b
--+--------- ----+-----------
1|want this 1 | want this
2|want this 2 | want this
20|want this 20 | want this
29|want this 29 | want this
40|want this 40 | want this
50|want this 50 | want this
60|want this 60 | want this
(7 rows) (7 rows)
QUERY: delete from rtest_nothn4; delete from rtest_nothn4;
QUERY: insert into rtest_nothn4 values (10, 'too small'); insert into rtest_nothn4 values (10, 'too small');
QUERY: insert into rtest_nothn4 values (50, 'too small'); insert into rtest_nothn4 values (50, 'too small');
QUERY: insert into rtest_nothn4 values (100, 'OK'); insert into rtest_nothn4 values (100, 'OK');
QUERY: insert into rtest_nothn4 values (200, 'OK'); insert into rtest_nothn4 values (200, 'OK');
QUERY: insert into rtest_nothn2 select * from rtest_nothn4; insert into rtest_nothn2 select * from rtest_nothn4;
QUERY: select * from rtest_nothn2; select * from rtest_nothn2;
a|b a | b
-+- ---+---
(0 rows) (0 rows)
QUERY: select * from rtest_nothn3; select * from rtest_nothn3;
a|b a | b
---+-- -----+----
100|OK 100 | OK
200|OK 200 | OK
(2 rows) (2 rows)
QUERY: create table rtest_view1 (a int4, b text, v bool); create table rtest_view1 (a int4, b text, v bool);
QUERY: create table rtest_view2 (a int4); create table rtest_view2 (a int4);
QUERY: create table rtest_view3 (a int4, b text); create table rtest_view3 (a int4, b text);
QUERY: create table rtest_view4 (a int4, b text, c int4); create table rtest_view4 (a int4, b text, c int4);
QUERY: create view rtest_vview1 as select a, b from rtest_view1 X 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); 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; 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 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); 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 create view rtest_vview4 as select X.a, X.b, count(Y.a) as refcount
from rtest_view1 X, rtest_view2 Y from rtest_view1 X, rtest_view2 Y
where X.a = Y.a where X.a = Y.a
group by X.a, X.b; group by X.a, X.b;
QUERY: create function rtest_viewfunc1(int4) returns int4 as create function rtest_viewfunc1(int4) returns int4 as
'select count(*) from rtest_view2 where a = $1' 'select count(*) from rtest_view2 where a = $1'
language 'sql'; language 'sql';
QUERY: create view rtest_vview5 as select a, b, rtest_viewfunc1(a) as refcount create view rtest_vview5 as select a, b, rtest_viewfunc1(a) as refcount
from rtest_view1; from rtest_view1;
QUERY: insert into rtest_view1 values (1, 'item 1', 't'); insert into rtest_view1 values (1, 'item 1', 't');
QUERY: insert into rtest_view1 values (2, 'item 2', 't'); insert into rtest_view1 values (2, 'item 2', 't');
QUERY: insert into rtest_view1 values (3, 'item 3', 't'); insert into rtest_view1 values (3, 'item 3', 't');
QUERY: insert into rtest_view1 values (4, 'item 4', 'f'); insert into rtest_view1 values (4, 'item 4', 'f');
QUERY: insert into rtest_view1 values (5, 'item 5', 't'); insert into rtest_view1 values (5, 'item 5', 't');
QUERY: insert into rtest_view1 values (6, 'item 6', 'f'); insert into rtest_view1 values (6, 'item 6', 'f');
QUERY: insert into rtest_view1 values (7, 'item 7', 't'); insert into rtest_view1 values (7, 'item 7', 't');
QUERY: insert into rtest_view1 values (8, 'item 8', 't'); insert into rtest_view1 values (8, 'item 8', 't');
QUERY: insert into rtest_view2 values (2); insert into rtest_view2 values (2);
QUERY: insert into rtest_view2 values (2); insert into rtest_view2 values (2);
QUERY: insert into rtest_view2 values (4); insert into rtest_view2 values (4);
QUERY: insert into rtest_view2 values (5); insert into rtest_view2 values (5);
QUERY: insert into rtest_view2 values (7); insert into rtest_view2 values (7);
QUERY: insert into rtest_view2 values (7); insert into rtest_view2 values (7);
QUERY: insert into rtest_view2 values (7); insert into rtest_view2 values (7);
QUERY: insert into rtest_view2 values (7); insert into rtest_view2 values (7);
QUERY: select * from rtest_vview1; select * from rtest_vview1;
a|b a | b
-+------ ---+--------
2|item 2 2 | item 2
4|item 4 4 | item 4
5|item 5 5 | item 5
7|item 7 7 | item 7
(4 rows) (4 rows)
QUERY: select * from rtest_vview2; select * from rtest_vview2;
a|b a | b
-+------ ---+--------
1|item 1 1 | item 1
2|item 2 2 | item 2
3|item 3 3 | item 3
5|item 5 5 | item 5
7|item 7 7 | item 7
8|item 8 8 | item 8
(6 rows) (6 rows)
QUERY: select * from rtest_vview3; select * from rtest_vview3;
a|b a | b
-+------ ---+--------
2|item 2 2 | item 2
5|item 5 5 | item 5
7|item 7 7 | item 7
(3 rows) (3 rows)
QUERY: select * from rtest_vview4; select * from rtest_vview4;
a|b |refcount a | b | refcount
-+------+-------- ---+--------+----------
2|item 2| 2 2 | item 2 | 2
4|item 4| 1 4 | item 4 | 1
5|item 5| 1 5 | item 5 | 1
7|item 7| 4 7 | item 7 | 4
(4 rows) (4 rows)
QUERY: select * from rtest_vview5; select * from rtest_vview5;
a|b |refcount a | b | refcount
-+------+-------- ---+--------+----------
1|item 1| 0 1 | item 1 | 0
2|item 2| 2 2 | item 2 | 2
3|item 3| 0 3 | item 3 | 0
4|item 4| 1 4 | item 4 | 1
5|item 5| 1 5 | item 5 | 1
6|item 6| 0 6 | item 6 | 0
7|item 7| 4 7 | item 7 | 4
8|item 8| 0 8 | item 8 | 0
(8 rows) (8 rows)
QUERY: insert into rtest_view3 select * from rtest_vview1 where a < 7; insert into rtest_view3 select * from rtest_vview1 where a < 7;
QUERY: select * from rtest_view3; select * from rtest_view3;
a|b a | b
-+------ ---+--------
2|item 2 2 | item 2
4|item 4 4 | item 4
5|item 5 5 | item 5
(3 rows) (3 rows)
QUERY: delete from rtest_view3; delete from rtest_view3;
QUERY: insert into rtest_view3 select * from rtest_vview2 where a != 5 and b !~ '2'; insert into rtest_view3 select * from rtest_vview2 where a != 5 and b !~ '2';
QUERY: select * from rtest_view3; select * from rtest_view3;
a|b a | b
-+------ ---+--------
1|item 1 1 | item 1
3|item 3 3 | item 3
7|item 7 7 | item 7
8|item 8 8 | item 8
(4 rows) (4 rows)
QUERY: delete from rtest_view3; delete from rtest_view3;
QUERY: insert into rtest_view3 select * from rtest_vview3; insert into rtest_view3 select * from rtest_vview3;
QUERY: select * from rtest_view3; select * from rtest_view3;
a|b a | b
-+------ ---+--------
2|item 2 2 | item 2
5|item 5 5 | item 5
7|item 7 7 | item 7
(3 rows) (3 rows)
QUERY: delete from rtest_view3; delete from rtest_view3;
QUERY: insert into rtest_view4 select * from rtest_vview4 where 3 > refcount; insert into rtest_view4 select * from rtest_vview4 where 3 > refcount;
QUERY: select * from rtest_view4; select * from rtest_view4;
a|b |c a | b | c
-+------+- ---+--------+---
2|item 2|2 2 | item 2 | 2
4|item 4|1 4 | item 4 | 1
5|item 5|1 5 | item 5 | 1
(3 rows) (3 rows)
QUERY: delete from rtest_view4; delete from rtest_view4;
QUERY: insert into rtest_view4 select * from rtest_vview5 where a > 2 and refcount = 0; insert into rtest_view4 select * from rtest_vview5 where a > 2 and refcount = 0;
QUERY: select * from rtest_view4; select * from rtest_view4;
a|b |c a | b | c
-+------+- ---+--------+---
3|item 3|0 3 | item 3 | 0
6|item 6|0 6 | item 6 | 0
8|item 8|0 8 | item 8 | 0
(3 rows) (3 rows)
QUERY: delete from rtest_view4; delete from rtest_view4;
QUERY: create table rtest_comp ( --
-- Test for computations in views
--
create table rtest_comp (
part text, part text,
unit char(4), unit char(4),
size float size float
); );
QUERY: create table rtest_unitfact ( create table rtest_unitfact (
unit char(4), unit char(4),
factor float factor float
); );
QUERY: create view rtest_vcomp as create view rtest_vcomp as
select X.part, (X.size * Y.factor) as size_in_cm select X.part, (X.size * Y.factor) as size_in_cm
from rtest_comp X, rtest_unitfact Y from rtest_comp X, rtest_unitfact Y
where X.unit = Y.unit; where X.unit = Y.unit;
QUERY: insert into rtest_unitfact values ('m', 100.0); insert into rtest_unitfact values ('m', 100.0);
QUERY: insert into rtest_unitfact values ('cm', 1.0); insert into rtest_unitfact values ('cm', 1.0);
QUERY: insert into rtest_unitfact values ('inch', 2.54); insert into rtest_unitfact values ('inch', 2.54);
QUERY: insert into rtest_comp values ('p1', 'm', 5.0); insert into rtest_comp values ('p1', 'm', 5.0);
QUERY: insert into rtest_comp values ('p2', 'm', 3.0); insert into rtest_comp values ('p2', 'm', 3.0);
QUERY: insert into rtest_comp values ('p3', 'cm', 5.0); insert into rtest_comp values ('p3', 'cm', 5.0);
QUERY: insert into rtest_comp values ('p4', 'cm', 15.0); insert into rtest_comp values ('p4', 'cm', 15.0);
QUERY: insert into rtest_comp values ('p5', 'inch', 7.0); insert into rtest_comp values ('p5', 'inch', 7.0);
QUERY: insert into rtest_comp values ('p6', 'inch', 4.4); insert into rtest_comp values ('p6', 'inch', 4.4);
QUERY: select * from rtest_vcomp order by part; select * from rtest_vcomp order by part;
part|size_in_cm part | size_in_cm
----+---------- ------+------------
p1 | 500 p1 | 500
p2 | 300 p2 | 300
p3 | 5 p3 | 5
p4 | 15 p4 | 15
p5 | 17.78 p5 | 17.78
p6 | 11.176 p6 | 11.176
(6 rows) (6 rows)
QUERY: select * from rtest_vcomp where size_in_cm > 10.0 order by size_in_cm using >; select * from rtest_vcomp where size_in_cm > 10.0 order by size_in_cm using >;
part|size_in_cm part | size_in_cm
----+---------- ------+------------
p1 | 500 p1 | 500
p2 | 300 p2 | 300
p5 | 17.78 p5 | 17.78
p4 | 15 p4 | 15
p6 | 11.176 p6 | 11.176
(5 rows) (5 rows)
QUERY: CREATE TABLE shoe_data ( --
shoename char(10), -- In addition run the (slightly modified) queries from the
sh_avail integer, -- programmers manual section on the rule system.
slcolor char(10), --
slminlen float, CREATE TABLE shoe_data (
slmaxlen float, shoename char(10), -- primary key
slunit char(8) sh_avail integer, -- available # of pairs
slcolor char(10), -- preferred shoelace color
slminlen float, -- miminum shoelace length
slmaxlen float, -- maximum shoelace length
slunit char(8) -- length unit
); );
QUERY: CREATE TABLE shoelace_data ( CREATE TABLE shoelace_data (
sl_name char(10), sl_name char(10), -- primary key
sl_avail integer, sl_avail integer, -- available # of pairs
sl_color char(10), sl_color char(10), -- shoelace color
sl_len float, sl_len float, -- shoelace length
sl_unit char(8) sl_unit char(8) -- length unit
); );
QUERY: CREATE TABLE unit ( CREATE TABLE unit (
un_name char(8), un_name char(8), -- the primary key
un_fact float un_fact float -- factor to transform to cm
); );
QUERY: CREATE VIEW shoe AS CREATE VIEW shoe AS
SELECT sh.shoename, SELECT sh.shoename,
sh.sh_avail, sh.sh_avail,
sh.slcolor, sh.slcolor,
...@@ -879,7 +954,7 @@ QUERY: CREATE VIEW shoe AS ...@@ -879,7 +954,7 @@ QUERY: CREATE VIEW shoe AS
sh.slunit sh.slunit
FROM shoe_data sh, unit un FROM shoe_data sh, unit un
WHERE sh.slunit = un.un_name; WHERE sh.slunit = un.un_name;
QUERY: CREATE VIEW shoelace AS CREATE VIEW shoelace AS
SELECT s.sl_name, SELECT s.sl_name,
s.sl_avail, s.sl_avail,
s.sl_color, s.sl_color,
...@@ -888,7 +963,7 @@ QUERY: CREATE VIEW shoelace AS ...@@ -888,7 +963,7 @@ QUERY: CREATE VIEW shoelace AS
s.sl_len * u.un_fact AS sl_len_cm s.sl_len * u.un_fact AS sl_len_cm
FROM shoelace_data s, unit u FROM shoelace_data s, unit u
WHERE s.sl_unit = u.un_name; WHERE s.sl_unit = u.un_name;
QUERY: CREATE VIEW shoe_ready AS CREATE VIEW shoe_ready AS
SELECT rsh.shoename, SELECT rsh.shoename,
rsh.sh_avail, rsh.sh_avail,
rsl.sl_name, rsl.sl_name,
...@@ -898,48 +973,52 @@ QUERY: CREATE VIEW shoe_ready AS ...@@ -898,48 +973,52 @@ QUERY: CREATE VIEW shoe_ready AS
WHERE rsl.sl_color = rsh.slcolor WHERE rsl.sl_color = rsh.slcolor
AND rsl.sl_len_cm >= rsh.slminlen_cm AND rsl.sl_len_cm >= rsh.slminlen_cm
AND rsl.sl_len_cm <= rsh.slmaxlen_cm; AND rsl.sl_len_cm <= rsh.slmaxlen_cm;
QUERY: INSERT INTO unit VALUES ('cm', 1.0); INSERT INTO unit VALUES ('cm', 1.0);
QUERY: INSERT INTO unit VALUES ('m', 100.0); INSERT INTO unit VALUES ('m', 100.0);
QUERY: INSERT INTO unit VALUES ('inch', 2.54); INSERT INTO unit VALUES ('inch', 2.54);
QUERY: INSERT INTO shoe_data VALUES ('sh1', 2, 'black', 70.0, 90.0, 'cm'); 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'); 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'); 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'); 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'); INSERT INTO shoelace_data VALUES ('sl1', 5, 'black', 80.0, 'cm');
QUERY: INSERT INTO shoelace_data VALUES ('sl2', 6, 'black', 100.0, 'cm'); INSERT INTO shoelace_data VALUES ('sl2', 6, 'black', 100.0, 'cm');
QUERY: INSERT INTO shoelace_data VALUES ('sl3', 0, 'black', 35.0 , 'inch'); INSERT INTO shoelace_data VALUES ('sl3', 0, 'black', 35.0 , 'inch');
QUERY: INSERT INTO shoelace_data VALUES ('sl4', 8, 'black', 40.0 , 'inch'); INSERT INTO shoelace_data VALUES ('sl4', 8, 'black', 40.0 , 'inch');
QUERY: INSERT INTO shoelace_data VALUES ('sl5', 4, 'brown', 1.0 , 'm'); INSERT INTO shoelace_data VALUES ('sl5', 4, 'brown', 1.0 , 'm');
QUERY: INSERT INTO shoelace_data VALUES ('sl6', 0, 'brown', 0.9 , 'm'); INSERT INTO shoelace_data VALUES ('sl6', 0, 'brown', 0.9 , 'm');
QUERY: INSERT INTO shoelace_data VALUES ('sl7', 7, 'brown', 60 , 'cm'); INSERT INTO shoelace_data VALUES ('sl7', 7, 'brown', 60 , 'cm');
QUERY: INSERT INTO shoelace_data VALUES ('sl8', 1, 'brown', 40 , 'inch'); INSERT INTO shoelace_data VALUES ('sl8', 1, 'brown', 40 , 'inch');
QUERY: SELECT * FROM shoelace ORDER BY sl_name; -- SELECTs in doc
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm SELECT * FROM shoelace ORDER BY sl_name;
----------+--------+----------+------+--------+--------- 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 sl1 | 5 | black | 80 | cm | 80
sl3 | 0|black | 35|inch | 88.9 sl2 | 6 | black | 100 | cm | 100
sl4 | 8|black | 40|inch | 101.6 sl3 | 0 | black | 35 | inch | 88.9
sl5 | 4|brown | 1|m | 100 sl4 | 8 | black | 40 | inch | 101.6
sl6 | 0|brown | 0.9|m | 90 sl5 | 4 | brown | 1 | m | 100
sl7 | 7|brown | 60|cm | 60 sl6 | 0 | brown | 0.9 | m | 90
sl8 | 1|brown | 40|inch | 101.6 sl7 | 7 | brown | 60 | cm | 60
sl8 | 1 | brown | 40 | inch | 101.6
(8 rows) (8 rows)
QUERY: SELECT * FROM shoe_ready WHERE total_avail >= 2; SELECT * FROM shoe_ready WHERE total_avail >= 2;
shoename |sh_avail|sl_name |sl_avail|total_avail shoename | sh_avail | sl_name | sl_avail | total_avail
----------+--------+----------+--------+----------- ------------+----------+------------+----------+-------------
sh1 | 2|sl1 | 5| 2 sh1 | 2 | sl1 | 5 | 2
sh3 | 4|sl7 | 7| 4 sh3 | 4 | sl7 | 7 | 4
(2 rows) (2 rows)
QUERY: CREATE TABLE shoelace_log ( CREATE TABLE shoelace_log (
sl_name char(10), sl_name char(10), -- shoelace changed
sl_avail integer, sl_avail integer, -- new available value
log_who name, log_who name, -- who did it
log_when datetime log_when datetime -- when
); );
QUERY: CREATE RULE log_shoelace AS ON UPDATE TO shoelace_data -- Want "log_who" to be CURRENT_USER,
-- but that is non-portable for the regression test
-- - thomas 1999-02-21
CREATE RULE log_shoelace AS ON UPDATE TO shoelace_data
WHERE NEW.sl_avail != OLD.sl_avail WHERE NEW.sl_avail != OLD.sl_avail
DO INSERT INTO shoelace_log VALUES ( DO INSERT INTO shoelace_log VALUES (
NEW.sl_name, NEW.sl_name,
...@@ -947,14 +1026,14 @@ QUERY: CREATE RULE log_shoelace AS ON UPDATE TO shoelace_data ...@@ -947,14 +1026,14 @@ QUERY: CREATE RULE log_shoelace AS ON UPDATE TO shoelace_data
'Al Bundy', 'Al Bundy',
'epoch'::text 'epoch'::text
); );
QUERY: UPDATE shoelace_data SET sl_avail = 6 WHERE sl_name = 'sl7'; UPDATE shoelace_data SET sl_avail = 6 WHERE sl_name = 'sl7';
QUERY: SELECT * FROM shoelace_log; SELECT * FROM shoelace_log;
sl_name |sl_avail|log_who |log_when sl_name | sl_avail | log_who | log_when
----------+--------+--------+-------- ------------+----------+----------+----------
sl7 | 6|Al Bundy|epoch sl7 | 6 | Al Bundy | epoch
(1 row) (1 row)
QUERY: CREATE RULE shoelace_ins AS ON INSERT TO shoelace CREATE RULE shoelace_ins AS ON INSERT TO shoelace
DO INSTEAD DO INSTEAD
INSERT INTO shoelace_data VALUES ( INSERT INTO shoelace_data VALUES (
NEW.sl_name, NEW.sl_name,
...@@ -962,7 +1041,7 @@ QUERY: CREATE RULE shoelace_ins AS ON INSERT TO shoelace ...@@ -962,7 +1041,7 @@ QUERY: CREATE RULE shoelace_ins AS ON INSERT TO shoelace
NEW.sl_color, NEW.sl_color,
NEW.sl_len, NEW.sl_len,
NEW.sl_unit); NEW.sl_unit);
QUERY: CREATE RULE shoelace_upd AS ON UPDATE TO shoelace CREATE RULE shoelace_upd AS ON UPDATE TO shoelace
DO INSTEAD DO INSTEAD
UPDATE shoelace_data SET UPDATE shoelace_data SET
sl_name = NEW.sl_name, sl_name = NEW.sl_name,
...@@ -971,154 +1050,157 @@ QUERY: CREATE RULE shoelace_upd AS ON UPDATE TO shoelace ...@@ -971,154 +1050,157 @@ QUERY: CREATE RULE shoelace_upd AS ON UPDATE TO shoelace
sl_len = NEW.sl_len, sl_len = NEW.sl_len,
sl_unit = NEW.sl_unit sl_unit = NEW.sl_unit
WHERE sl_name = OLD.sl_name; WHERE sl_name = OLD.sl_name;
QUERY: CREATE RULE shoelace_del AS ON DELETE TO shoelace CREATE RULE shoelace_del AS ON DELETE TO shoelace
DO INSTEAD DO INSTEAD
DELETE FROM shoelace_data DELETE FROM shoelace_data
WHERE sl_name = OLD.sl_name; WHERE sl_name = OLD.sl_name;
QUERY: CREATE TABLE shoelace_arrive ( CREATE TABLE shoelace_arrive (
arr_name char(10), arr_name char(10),
arr_quant integer arr_quant integer
); );
QUERY: CREATE TABLE shoelace_ok ( CREATE TABLE shoelace_ok (
ok_name char(10), ok_name char(10),
ok_quant integer ok_quant integer
); );
QUERY: CREATE RULE shoelace_ok_ins AS ON INSERT TO shoelace_ok CREATE RULE shoelace_ok_ins AS ON INSERT TO shoelace_ok
DO INSTEAD DO INSTEAD
UPDATE shoelace SET UPDATE shoelace SET
sl_avail = sl_avail + NEW.ok_quant sl_avail = sl_avail + NEW.ok_quant
WHERE sl_name = NEW.ok_name; WHERE sl_name = NEW.ok_name;
QUERY: INSERT INTO shoelace_arrive VALUES ('sl3', 10); INSERT INTO shoelace_arrive VALUES ('sl3', 10);
QUERY: INSERT INTO shoelace_arrive VALUES ('sl6', 20); INSERT INTO shoelace_arrive VALUES ('sl6', 20);
QUERY: INSERT INTO shoelace_arrive VALUES ('sl8', 20); INSERT INTO shoelace_arrive VALUES ('sl8', 20);
QUERY: SELECT * FROM shoelace ORDER BY sl_name; SELECT * FROM shoelace ORDER BY sl_name;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
----------+--------+----------+------+--------+--------- ------------+----------+------------+--------+----------+-----------
sl1 | 5|black | 80|cm | 80 sl1 | 5 | black | 80 | cm | 80
sl2 | 6|black | 100|cm | 100 sl2 | 6 | black | 100 | cm | 100
sl3 | 0|black | 35|inch | 88.9 sl3 | 0 | black | 35 | inch | 88.9
sl4 | 8|black | 40|inch | 101.6 sl4 | 8 | black | 40 | inch | 101.6
sl5 | 4|brown | 1|m | 100 sl5 | 4 | brown | 1 | m | 100
sl6 | 0|brown | 0.9|m | 90 sl6 | 0 | brown | 0.9 | m | 90
sl7 | 6|brown | 60|cm | 60 sl7 | 6 | brown | 60 | cm | 60
sl8 | 1|brown | 40|inch | 101.6 sl8 | 1 | brown | 40 | inch | 101.6
(8 rows) (8 rows)
QUERY: insert into shoelace_ok select * from shoelace_arrive; insert into shoelace_ok select * from shoelace_arrive;
QUERY: SELECT * FROM shoelace ORDER BY sl_name; SELECT * FROM shoelace ORDER BY sl_name;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
----------+--------+----------+------+--------+--------- ------------+----------+------------+--------+----------+-----------
sl1 | 5|black | 80|cm | 80 sl1 | 5 | black | 80 | cm | 80
sl2 | 6|black | 100|cm | 100 sl2 | 6 | black | 100 | cm | 100
sl3 | 10|black | 35|inch | 88.9 sl3 | 10 | black | 35 | inch | 88.9
sl4 | 8|black | 40|inch | 101.6 sl4 | 8 | black | 40 | inch | 101.6
sl5 | 4|brown | 1|m | 100 sl5 | 4 | brown | 1 | m | 100
sl6 | 20|brown | 0.9|m | 90 sl6 | 20 | brown | 0.9 | m | 90
sl7 | 6|brown | 60|cm | 60 sl7 | 6 | brown | 60 | cm | 60
sl8 | 21|brown | 40|inch | 101.6 sl8 | 21 | brown | 40 | inch | 101.6
(8 rows) (8 rows)
QUERY: SELECT * FROM shoelace_log ORDER BY sl_name; SELECT * FROM shoelace_log ORDER BY sl_name;
sl_name |sl_avail|log_who |log_when sl_name | sl_avail | log_who | log_when
----------+--------+--------+-------- ------------+----------+----------+----------
sl3 | 10|Al Bundy|epoch sl3 | 10 | Al Bundy | epoch
sl6 | 20|Al Bundy|epoch sl6 | 20 | Al Bundy | epoch
sl7 | 6|Al Bundy|epoch sl7 | 6 | Al Bundy | epoch
sl8 | 21|Al Bundy|epoch sl8 | 21 | Al Bundy | epoch
(4 rows) (4 rows)
QUERY: CREATE VIEW shoelace_obsolete AS CREATE VIEW shoelace_obsolete AS
SELECT * FROM shoelace WHERE NOT EXISTS SELECT * FROM shoelace WHERE NOT EXISTS
(SELECT shoename FROM shoe WHERE slcolor = sl_color); (SELECT shoename FROM shoe WHERE slcolor = sl_color);
QUERY: CREATE VIEW shoelace_candelete AS CREATE VIEW shoelace_candelete AS
SELECT * FROM shoelace_obsolete WHERE sl_avail = 0; SELECT * FROM shoelace_obsolete WHERE sl_avail = 0;
QUERY: insert into shoelace values ('sl9', 0, 'pink', 35.0, 'inch', 0.0); 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); insert into shoelace values ('sl10', 1000, 'magenta', 40.0, 'inch', 0.0);
QUERY: SELECT * FROM shoelace_obsolete; SELECT * FROM shoelace_obsolete;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
----------+--------+----------+------+--------+--------- ------------+----------+------------+--------+----------+-----------
sl9 | 0|pink | 35|inch | 88.9 sl9 | 0 | pink | 35 | inch | 88.9
sl10 | 1000|magenta | 40|inch | 101.6 sl10 | 1000 | magenta | 40 | inch | 101.6
(2 rows) (2 rows)
QUERY: SELECT * FROM shoelace_candelete; SELECT * FROM shoelace_candelete;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
----------+--------+----------+------+--------+--------- ------------+----------+------------+--------+----------+-----------
sl9 | 0|pink | 35|inch | 88.9 sl9 | 0 | pink | 35 | inch | 88.9
(1 row) (1 row)
QUERY: DELETE FROM shoelace WHERE EXISTS DELETE FROM shoelace WHERE EXISTS
(SELECT * FROM shoelace_candelete (SELECT * FROM shoelace_candelete
WHERE sl_name = shoelace.sl_name); WHERE sl_name = shoelace.sl_name);
QUERY: SELECT * FROM shoelace ORDER BY sl_name; SELECT * FROM shoelace ORDER BY sl_name;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
----------+--------+----------+------+--------+--------- ------------+----------+------------+--------+----------+-----------
sl1 | 5|black | 80|cm | 80 sl1 | 5 | black | 80 | cm | 80
sl10 | 1000|magenta | 40|inch | 101.6 sl10 | 1000 | magenta | 40 | inch | 101.6
sl2 | 6|black | 100|cm | 100 sl2 | 6 | black | 100 | cm | 100
sl3 | 10|black | 35|inch | 88.9 sl3 | 10 | black | 35 | inch | 88.9
sl4 | 8|black | 40|inch | 101.6 sl4 | 8 | black | 40 | inch | 101.6
sl5 | 4|brown | 1|m | 100 sl5 | 4 | brown | 1 | m | 100
sl6 | 20|brown | 0.9|m | 90 sl6 | 20 | brown | 0.9 | m | 90
sl7 | 6|brown | 60|cm | 60 sl7 | 6 | brown | 60 | cm | 60
sl8 | 21|brown | 40|inch | 101.6 sl8 | 21 | brown | 40 | inch | 101.6
(9 rows) (9 rows)
QUERY: SELECT viewname, definition FROM pg_views ORDER BY viewname; --
viewname |definition -- Check that ruleutils are working
------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --
iexit |SELECT ih.name, ih.thepath, interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE (ih.thepath ## r.thepath); SELECT viewname, definition FROM pg_views ORDER BY viewname;
pg_indexes |SELECT c.relname AS tablename, i.relname AS indexname, pg_get_indexdef(x.indexrelid) AS indexdef FROM pg_index x, pg_class c, pg_class i WHERE ((c.oid = x.indrelid) AND (i.oid = x.indexrelid)); viewname | definition
pg_rules |SELECT c.relname AS tablename, r.rulename, pg_get_ruledef(r.rulename) AS definition FROM pg_rewrite r, pg_class c WHERE ((r.rulename !~ '^_RET'::text) AND (c.oid = r.ev_class)); --------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pg_tables |SELECT c.relname AS tablename, pg_get_userbyid(c.relowner) AS tableowner, c.relhasindex AS hasindexes, c.relhasrules AS hasrules, (c.reltriggers > 0) AS hastriggers FROM pg_class c WHERE (((c.relkind = 'r'::"char") OR (c.relkind = 's'::"char")) AND (NOT (EXISTS (SELECT pg_rewrite.rulename FROM pg_rewrite WHERE ((pg_rewrite.ev_class = c.oid) AND (pg_rewrite.ev_type = '1'::"char")))))); iexit | SELECT ih.name, ih.thepath, interpt_pp(ih.thepath, r.thepath) AS exit FROM ihighway ih, ramp r WHERE (ih.thepath ## r.thepath);
pg_user |SELECT pg_shadow.usename, pg_shadow.usesysid, pg_shadow.usecreatedb, pg_shadow.usetrace, pg_shadow.usesuper, pg_shadow.usecatupd, '********'::text AS passwd, pg_shadow.valuntil FROM pg_shadow; pg_indexes | SELECT c.relname AS tablename, i.relname AS indexname, pg_get_indexdef(x.indexrelid) AS indexdef FROM pg_index x, pg_class c, pg_class i WHERE ((c.oid = x.indrelid) AND (i.oid = x.indexrelid));
pg_views |SELECT c.relname AS viewname, pg_get_userbyid(c.relowner) AS viewowner, pg_get_viewdef(c.relname) AS definition FROM pg_class c WHERE (c.relhasrules AND (EXISTS (SELECT r.rulename FROM pg_rewrite r WHERE ((r.ev_class = c.oid) AND (r.ev_type = '1'::"char"))))); pg_rules | SELECT c.relname AS tablename, r.rulename, pg_get_ruledef(r.rulename) AS definition FROM pg_rewrite r, pg_class c WHERE ((r.rulename !~ '^_RET'::text) AND (c.oid = r.ev_class));
rtest_v1 |SELECT rtest_t1.a, rtest_t1.b FROM rtest_t1; pg_tables | SELECT c.relname AS tablename, pg_get_userbyid(c.relowner) AS tableowner, c.relhasindex AS hasindexes, c.relhasrules AS hasrules, (c.reltriggers > 0) AS hastriggers FROM pg_class c WHERE (((c.relkind = 'r'::"char") OR (c.relkind = 's'::"char")) AND (NOT (EXISTS (SELECT pg_rewrite.rulename FROM pg_rewrite WHERE ((pg_rewrite.ev_class = c.oid) AND (pg_rewrite.ev_type = '1'::"char"))))));
rtest_vcomp |SELECT x.part, (x.size * y.factor) AS size_in_cm FROM rtest_comp x, rtest_unitfact y WHERE (x.unit = y.unit); pg_user | SELECT pg_shadow.usename, pg_shadow.usesysid, pg_shadow.usecreatedb, pg_shadow.usetrace, pg_shadow.usesuper, pg_shadow.usecatupd, '********'::text AS passwd, pg_shadow.valuntil FROM pg_shadow;
rtest_vview1 |SELECT x.a, x.b FROM rtest_view1 x WHERE (0 < (SELECT count(*) AS count FROM rtest_view2 y WHERE (y.a = x.a))); pg_views | SELECT c.relname AS viewname, pg_get_userbyid(c.relowner) AS viewowner, pg_get_viewdef(c.relname) AS definition FROM pg_class c WHERE (c.relhasrules AND (EXISTS (SELECT r.rulename FROM pg_rewrite r WHERE ((r.ev_class = c.oid) AND (r.ev_type = '1'::"char")))));
rtest_vview2 |SELECT rtest_view1.a, rtest_view1.b FROM rtest_view1 WHERE rtest_view1.v; rtest_v1 | SELECT rtest_t1.a, rtest_t1.b FROM rtest_t1;
rtest_vview3 |SELECT x.a, x.b FROM rtest_vview2 x WHERE (0 < (SELECT count(*) AS count FROM rtest_view2 y WHERE (y.a = x.a))); rtest_vcomp | SELECT x.part, (x.size * y.factor) AS size_in_cm FROM rtest_comp x, rtest_unitfact y WHERE (x.unit = y.unit);
rtest_vview4 |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; rtest_vview1 | SELECT x.a, x.b FROM rtest_view1 x WHERE (0 < (SELECT count(*) AS count FROM rtest_view2 y WHERE (y.a = x.a)));
rtest_vview5 |SELECT rtest_view1.a, rtest_view1.b, rtest_viewfunc1(rtest_view1.a) AS refcount FROM rtest_view1; rtest_vview2 | SELECT rtest_view1.a, rtest_view1.b FROM rtest_view1 WHERE rtest_view1.v;
shoe |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); rtest_vview3 | SELECT x.a, x.b FROM rtest_vview2 x WHERE (0 < (SELECT count(*) AS count FROM rtest_view2 y WHERE (y.a = x.a)));
shoe_ready |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)); rtest_vview4 | 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;
shoelace |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); rtest_vview5 | SELECT rtest_view1.a, rtest_view1.b, rtest_viewfunc1(rtest_view1.a) AS refcount FROM rtest_view1;
shoelace_candelete|SELECT shoelace_obsolete.sl_name, shoelace_obsolete.sl_avail, shoelace_obsolete.sl_color, shoelace_obsolete.sl_len, shoelace_obsolete.sl_unit, shoelace_obsolete.sl_len_cm FROM shoelace_obsolete WHERE (shoelace_obsolete.sl_avail = 0); shoe | 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);
shoelace_obsolete |SELECT shoelace.sl_name, shoelace.sl_avail, shoelace.sl_color, shoelace.sl_len, shoelace.sl_unit, shoelace.sl_len_cm FROM shoelace WHERE (NOT (EXISTS (SELECT shoe.shoename FROM shoe WHERE (shoe.slcolor = shoelace.sl_color)))); shoe_ready | 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));
street |SELECT r.name, r.thepath, c.cname FROM road r, real_city c WHERE (c.outline ## r.thepath); shoelace | 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);
toyemp |SELECT emp.name, emp.age, emp."location", (12 * emp.salary) AS annualsal FROM emp; shoelace_candelete | SELECT shoelace_obsolete.sl_name, shoelace_obsolete.sl_avail, shoelace_obsolete.sl_color, shoelace_obsolete.sl_len, shoelace_obsolete.sl_unit, shoelace_obsolete.sl_len_cm FROM shoelace_obsolete WHERE (shoelace_obsolete.sl_avail = 0);
shoelace_obsolete | SELECT shoelace.sl_name, shoelace.sl_avail, shoelace.sl_color, shoelace.sl_len, shoelace.sl_unit, shoelace.sl_len_cm FROM shoelace WHERE (NOT (EXISTS (SELECT shoe.shoename FROM shoe WHERE (shoe.slcolor = shoelace.sl_color))));
street | SELECT r.name, r.thepath, c.cname FROM road r, real_city c WHERE (c.outline ## r.thepath);
toyemp | SELECT emp.name, emp.age, emp."location", (12 * emp.salary) AS annualsal FROM emp;
(20 rows) (20 rows)
QUERY: SELECT tablename, rulename, definition FROM pg_rules SELECT tablename, rulename, definition FROM pg_rules
ORDER BY tablename, rulename; ORDER BY tablename, rulename;
tablename |rulename |definition tablename | rulename | definition
-------------+---------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---------------+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rtest_emp |rtest_emp_del |CREATE RULE rtest_emp_del AS ON DELETE TO rtest_emp DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (old.ename, getpgusername(), 'fired'::bpchar, '$0.00'::money, old.salary); rtest_emp | rtest_emp_del | CREATE RULE rtest_emp_del AS ON DELETE TO rtest_emp DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (old.ename, getpgusername(), 'fired'::bpchar, '$0.00'::money, old.salary);
rtest_emp |rtest_emp_ins |CREATE RULE rtest_emp_ins AS ON INSERT TO rtest_emp DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (new.ename, getpgusername(), 'hired'::bpchar, new.salary, '$0.00'::money); rtest_emp | rtest_emp_ins | CREATE RULE rtest_emp_ins AS ON INSERT TO rtest_emp DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (new.ename, getpgusername(), 'hired'::bpchar, new.salary, '$0.00'::money);
rtest_emp |rtest_emp_upd |CREATE RULE rtest_emp_upd AS ON UPDATE TO rtest_emp WHERE (new.salary <> old.salary) DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (new.ename, getpgusername(), 'honored'::bpchar, new.salary, old.salary); rtest_emp | rtest_emp_upd | CREATE RULE rtest_emp_upd AS ON UPDATE TO rtest_emp WHERE (new.salary <> old.salary) DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (new.ename, getpgusername(), 'honored'::bpchar, new.salary, old.salary);
rtest_nothn1 |rtest_nothn_r1 |CREATE RULE rtest_nothn_r1 AS ON INSERT TO rtest_nothn1 WHERE ((new.a >= 10) AND (new.a < 20)) DO INSTEAD SELECT 1; rtest_nothn1 | rtest_nothn_r1 | CREATE RULE rtest_nothn_r1 AS ON INSERT TO rtest_nothn1 WHERE ((new.a >= 10) AND (new.a < 20)) DO INSTEAD SELECT 1;
rtest_nothn1 |rtest_nothn_r2 |CREATE RULE rtest_nothn_r2 AS ON INSERT TO rtest_nothn1 WHERE ((new.a >= 30) AND (new.a < 40)) DO INSTEAD NOTHING; rtest_nothn1 | rtest_nothn_r2 | CREATE RULE rtest_nothn_r2 AS ON INSERT TO rtest_nothn1 WHERE ((new.a >= 30) AND (new.a < 40)) DO INSTEAD NOTHING;
rtest_nothn2 |rtest_nothn_r3 |CREATE RULE rtest_nothn_r3 AS ON INSERT TO rtest_nothn2 WHERE (new.a >= 100) DO INSTEAD INSERT INTO rtest_nothn3 (a, b) VALUES (new.a, new.b); rtest_nothn2 | rtest_nothn_r3 | CREATE RULE rtest_nothn_r3 AS ON INSERT TO rtest_nothn2 WHERE (new.a >= 100) DO INSTEAD INSERT INTO rtest_nothn3 (a, b) VALUES (new.a, new.b);
rtest_nothn2 |rtest_nothn_r4 |CREATE RULE rtest_nothn_r4 AS ON INSERT TO rtest_nothn2 DO INSTEAD NOTHING; rtest_nothn2 | rtest_nothn_r4 | CREATE RULE rtest_nothn_r4 AS ON INSERT TO rtest_nothn2 DO INSTEAD NOTHING;
rtest_order1 |rtest_order_r1 |CREATE RULE rtest_order_r1 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 1 - this should run 3rd or 4th'::text); rtest_order1 | rtest_order_r1 | CREATE RULE rtest_order_r1 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 1 - this should run 3rd or 4th'::text);
rtest_order1 |rtest_order_r2 |CREATE RULE rtest_order_r2 AS ON INSERT TO rtest_order1 DO INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 2 - this should run 1st'::text); rtest_order1 | rtest_order_r2 | CREATE RULE rtest_order_r2 AS ON INSERT TO rtest_order1 DO INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 2 - this should run 1st'::text);
rtest_order1 |rtest_order_r3 |CREATE RULE rtest_order_r3 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 3 - this should run 3rd or 4th'::text); rtest_order1 | rtest_order_r3 | CREATE RULE rtest_order_r3 AS ON INSERT TO rtest_order1 DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 3 - this should run 3rd or 4th'::text);
rtest_order1 |rtest_order_r4 |CREATE RULE rtest_order_r4 AS ON INSERT TO rtest_order1 WHERE (rtest_order2.a < 100) DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 4 - this should run 2nd'::text); rtest_order1 | rtest_order_r4 | CREATE RULE rtest_order_r4 AS ON INSERT TO rtest_order1 WHERE (rtest_order2.a < 100) DO INSTEAD INSERT INTO rtest_order2 (a, b, c) VALUES (new.a, nextval('rtest_seq'::text), 'rule 4 - this should run 2nd'::text);
rtest_person |rtest_pers_del |CREATE RULE rtest_pers_del AS ON DELETE TO rtest_person DO DELETE FROM rtest_admin WHERE (rtest_admin.pname = old.pname); rtest_person | rtest_pers_del | CREATE RULE rtest_pers_del AS ON DELETE TO rtest_person DO DELETE FROM rtest_admin WHERE (rtest_admin.pname = old.pname);
rtest_person |rtest_pers_upd |CREATE RULE rtest_pers_upd AS ON UPDATE TO rtest_person DO UPDATE rtest_admin SET pname = new.pname WHERE (rtest_admin.pname = old.pname); rtest_person | rtest_pers_upd | CREATE RULE rtest_pers_upd AS ON UPDATE TO rtest_person DO UPDATE rtest_admin SET pname = new.pname WHERE (rtest_admin.pname = old.pname);
rtest_system |rtest_sys_del |CREATE RULE rtest_sys_del AS ON DELETE TO rtest_system DO (DELETE FROM rtest_interface WHERE (rtest_interface.sysname = old.sysname); DELETE FROM rtest_admin WHERE (rtest_admin.sysname = old.sysname); ); rtest_system | rtest_sys_del | CREATE RULE rtest_sys_del AS ON DELETE TO rtest_system DO (DELETE FROM rtest_interface WHERE (rtest_interface.sysname = old.sysname); DELETE FROM rtest_admin WHERE (rtest_admin.sysname = old.sysname); );
rtest_system |rtest_sys_upd |CREATE RULE rtest_sys_upd AS ON UPDATE TO rtest_system DO (UPDATE rtest_interface SET sysname = new.sysname WHERE (rtest_interface.sysname = old.sysname); UPDATE rtest_admin SET sysname = new.sysname WHERE (rtest_admin.sysname = old.sysname); ); rtest_system | rtest_sys_upd | CREATE RULE rtest_sys_upd AS ON UPDATE TO rtest_system DO (UPDATE rtest_interface SET sysname = new.sysname WHERE (rtest_interface.sysname = old.sysname); UPDATE rtest_admin SET sysname = new.sysname WHERE (rtest_admin.sysname = old.sysname); );
rtest_t4 |rtest_t4_ins1 |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 (a, b) VALUES (new.a, new.b); rtest_t4 | rtest_t4_ins1 | 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 (a, b) VALUES (new.a, new.b);
rtest_t4 |rtest_t4_ins2 |CREATE RULE rtest_t4_ins2 AS ON INSERT TO rtest_t4 WHERE ((new.a >= 20) AND (new.a < 30)) DO INSERT INTO rtest_t6 (a, b) VALUES (new.a, new.b); rtest_t4 | rtest_t4_ins2 | CREATE RULE rtest_t4_ins2 AS ON INSERT TO rtest_t4 WHERE ((new.a >= 20) AND (new.a < 30)) DO INSERT INTO rtest_t6 (a, b) VALUES (new.a, new.b);
rtest_t5 |rtest_t5_ins |CREATE RULE rtest_t5_ins AS ON INSERT TO rtest_t5 WHERE (new.a > 15) DO INSERT INTO rtest_t7 (a, b) VALUES (new.a, new.b); rtest_t5 | rtest_t5_ins | CREATE RULE rtest_t5_ins AS ON INSERT TO rtest_t5 WHERE (new.a > 15) DO INSERT INTO rtest_t7 (a, b) VALUES (new.a, new.b);
rtest_t6 |rtest_t6_ins |CREATE RULE rtest_t6_ins AS ON INSERT TO rtest_t6 WHERE (new.a > 25) DO INSTEAD INSERT INTO rtest_t8 (a, b) VALUES (new.a, new.b); rtest_t6 | rtest_t6_ins | CREATE RULE rtest_t6_ins AS ON INSERT TO rtest_t6 WHERE (new.a > 25) DO INSTEAD INSERT INTO rtest_t8 (a, b) VALUES (new.a, new.b);
rtest_v1 |rtest_v1_del |CREATE RULE rtest_v1_del AS ON DELETE TO rtest_v1 DO INSTEAD DELETE FROM rtest_t1 WHERE (rtest_t1.a = old.a); rtest_v1 | rtest_v1_del | CREATE RULE rtest_v1_del AS ON DELETE TO rtest_v1 DO INSTEAD DELETE FROM rtest_t1 WHERE (rtest_t1.a = old.a);
rtest_v1 |rtest_v1_ins |CREATE RULE rtest_v1_ins AS ON INSERT TO rtest_v1 DO INSTEAD INSERT INTO rtest_t1 (a, b) VALUES (new.a, new.b); rtest_v1 | rtest_v1_ins | CREATE RULE rtest_v1_ins AS ON INSERT TO rtest_v1 DO INSTEAD INSERT INTO rtest_t1 (a, b) VALUES (new.a, new.b);
rtest_v1 |rtest_v1_upd |CREATE RULE rtest_v1_upd AS ON UPDATE TO rtest_v1 DO INSTEAD UPDATE rtest_t1 SET a = new.a, b = new.b WHERE (rtest_t1.a = old.a); rtest_v1 | rtest_v1_upd | CREATE RULE rtest_v1_upd AS ON UPDATE TO rtest_v1 DO INSTEAD UPDATE rtest_t1 SET a = new.a, b = new.b WHERE (rtest_t1.a = old.a);
shoelace |shoelace_del |CREATE RULE shoelace_del AS ON DELETE TO shoelace DO INSTEAD DELETE FROM shoelace_data WHERE (shoelace_data.sl_name = old.sl_name); shoelace | shoelace_del | CREATE RULE shoelace_del AS ON DELETE TO shoelace DO INSTEAD DELETE FROM shoelace_data WHERE (shoelace_data.sl_name = old.sl_name);
shoelace |shoelace_ins |CREATE RULE shoelace_ins AS ON INSERT TO shoelace DO INSTEAD INSERT INTO shoelace_data (sl_name, sl_avail, sl_color, sl_len, sl_unit) VALUES (new.sl_name, new.sl_avail, new.sl_color, new.sl_len, new.sl_unit); shoelace | shoelace_ins | CREATE RULE shoelace_ins AS ON INSERT TO shoelace DO INSTEAD INSERT INTO shoelace_data (sl_name, sl_avail, sl_color, sl_len, sl_unit) VALUES (new.sl_name, new.sl_avail, new.sl_color, new.sl_len, new.sl_unit);
shoelace |shoelace_upd |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 (shoelace_data.sl_name = old.sl_name); shoelace | shoelace_upd | 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 (shoelace_data.sl_name = old.sl_name);
shoelace_data|log_shoelace |CREATE RULE log_shoelace AS ON UPDATE TO shoelace_data WHERE (new.sl_avail <> old.sl_avail) DO INSERT INTO shoelace_log (sl_name, sl_avail, log_who, log_when) VALUES (new.sl_name, new.sl_avail, 'Al Bundy'::name, datetime('epoch'::text)); shoelace_data | log_shoelace | CREATE RULE log_shoelace AS ON UPDATE TO shoelace_data WHERE (new.sl_avail <> old.sl_avail) DO INSERT INTO shoelace_log (sl_name, sl_avail, log_who, log_when) VALUES (new.sl_name, new.sl_avail, 'Al Bundy'::name, datetime('epoch'::text));
shoelace_ok |shoelace_ok_ins|CREATE RULE shoelace_ok_ins AS ON INSERT TO shoelace_ok DO INSTEAD UPDATE shoelace SET sl_avail = (shoelace.sl_avail + new.ok_quant) WHERE (shoelace.sl_name = new.ok_name); shoelace_ok | shoelace_ok_ins | CREATE RULE shoelace_ok_ins AS ON INSERT TO shoelace_ok DO INSTEAD UPDATE shoelace SET sl_avail = (shoelace.sl_avail + new.ok_quant) WHERE (shoelace.sl_name = new.ok_name);
(27 rows) (27 rows)
This source diff could not be displayed because it is too large. You can view the blob instead.
QUERY: CREATE TABLE temptest(col int); --
QUERY: CREATE INDEX i_temptest ON temptest(col); -- TEMP
QUERY: CREATE TEMP TABLE temptest(col int); -- Test temp relations and indexes
QUERY: CREATE INDEX i_temptest ON temptest(col); --
QUERY: DROP INDEX i_temptest; -- test temp table/index masking
QUERY: DROP TABLE temptest; CREATE TABLE temptest(col int);
QUERY: DROP INDEX i_temptest; CREATE INDEX i_temptest ON temptest(col);
QUERY: DROP TABLE temptest; CREATE TEMP TABLE temptest(col int);
QUERY: CREATE TABLE temptest(col int); CREATE INDEX i_temptest ON temptest(col);
QUERY: INSERT INTO temptest VALUES (1); DROP INDEX i_temptest;
QUERY: CREATE TEMP TABLE temptest(col int); DROP TABLE temptest;
QUERY: INSERT INTO temptest VALUES (2); DROP INDEX i_temptest;
QUERY: SELECT * FROM temptest; DROP TABLE temptest;
col -- test temp table selects
--- CREATE TABLE temptest(col int);
2 INSERT INTO temptest VALUES (1);
CREATE TEMP TABLE temptest(col int);
INSERT INTO temptest VALUES (2);
SELECT * FROM temptest;
col
-----
2
(1 row) (1 row)
QUERY: DROP TABLE temptest; DROP TABLE temptest;
QUERY: SELECT * FROM temptest; SELECT * FROM temptest;
col col
--- -----
1 1
(1 row) (1 row)
QUERY: DROP TABLE temptest; DROP TABLE temptest;
QUERY: CREATE TEMP TABLE temptest(col int); CREATE TEMP TABLE temptest(col int);
QUERY: SELECT * FROM temptest; -- test temp table deletion
\c regression
SELECT * FROM temptest;
ERROR: Relation 'temptest' does not exist ERROR: Relation 'temptest' does not exist
QUERY: BEGIN; --
QUERY: SELECT * -- TRANSACTIONS
--
BEGIN;
SELECT *
INTO TABLE xacttest INTO TABLE xacttest
FROM aggtest; FROM aggtest;
QUERY: INSERT INTO xacttest (a, b) VALUES (777, 777.777); INSERT INTO xacttest (a, b) VALUES (777, 777.777);
QUERY: END; END;
QUERY: SELECT a FROM xacttest WHERE a > 100; -- should retrieve one value--
a SELECT a FROM xacttest WHERE a > 100;
--- a
777 -----
777
(1 row) (1 row)
QUERY: BEGIN; BEGIN;
QUERY: CREATE TABLE disappear (a int4); CREATE TABLE disappear (a int4);
QUERY: DELETE FROM aggtest; DELETE FROM aggtest;
QUERY: SELECT * FROM aggtest; -- should be empty
a|b SELECT * FROM aggtest;
-+- a | b
---+---
(0 rows) (0 rows)
QUERY: ABORT; ABORT;
QUERY: SELECT oid FROM pg_class WHERE relname = 'disappear'; -- should not exist
oid SELECT oid FROM pg_class WHERE relname = 'disappear';
--- oid
-----
(0 rows) (0 rows)
QUERY: SELECT * FROM aggtest; -- should have members again
a| b SELECT * FROM aggtest;
---+------- a | b
56| 7.8 -----+---------
100| 99.097 56 | 7.8
0|0.09561 100 | 99.097
42| 324.78 0 | 0.09561
42 | 324.78
(4 rows) (4 rows)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment