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
-----
1
--
-- AGGREGATES
--
SELECT avg(four) AS avg_1 FROM onek;
avg_1
-------
1
(1 row)
QUERY: SELECT avg(a) AS avg_32 FROM aggtest WHERE a < 100;
avg_32
------
32
SELECT avg(a) AS avg_32 FROM aggtest WHERE a < 100;
avg_32
--------
32
(1 row)
QUERY: SELECT avg(b) AS avg_107_943 FROM aggtest;
avg_107_943
-----------
107.943
SELECT avg(b) AS avg_107_943 FROM aggtest;
avg_107_943
-------------
107.943
(1 row)
QUERY: SELECT avg(gpa) AS avg_3_4 FROM student;
avg_3_4
-------
3.4
SELECT avg(gpa) AS avg_3_4 FROM student;
avg_3_4
---------
3.4
(1 row)
QUERY: SELECT sum(four) AS sum_1500 FROM onek;
sum_1500
--------
1500
SELECT sum(four) AS sum_1500 FROM onek;
sum_1500
----------
1500
(1 row)
QUERY: SELECT sum(a) AS sum_198 FROM aggtest;
sum_198
-------
198
SELECT sum(a) AS sum_198 FROM aggtest;
sum_198
---------
198
(1 row)
SELECT sum(b) AS avg_431_773 FROM aggtest;
avg_431_773
-------------
431.773
(1 row)
QUERY: SELECT sum(b) AS avg_431_773 FROM aggtest;
avg_431_773
-----------
431.773
SELECT sum(gpa) AS avg_6_8 FROM student;
avg_6_8
---------
6.8
(1 row)
QUERY: SELECT sum(gpa) AS avg_6_8 FROM student;
avg_6_8
SELECT max(four) AS max_3 FROM onek;
max_3
-------
6.8
3
(1 row)
QUERY: SELECT max(four) AS max_3 FROM onek;
max_3
-----
3
SELECT max(a) AS max_100 FROM aggtest;
max_100
---------
100
(1 row)
QUERY: SELECT max(a) AS max_100 FROM aggtest;
max_100
-------
100
SELECT max(aggtest.b) AS max_324_78 FROM aggtest;
max_324_78
------------
324.78
(1 row)
QUERY: SELECT max(aggtest.b) AS max_324_78 FROM aggtest;
max_324_78
----------
324.78
SELECT max(student.gpa) AS max_3_7 FROM student;
max_3_7
---------
3.7
(1 row)
QUERY: SELECT max(student.gpa) AS max_3_7 FROM student;
max_3_7
-------
3.7
SELECT count(four) AS cnt_1000 FROM onek;
cnt_1000
----------
1000
(1 row)
QUERY: SELECT count(four) AS cnt_1000 FROM onek;
cnt_1000
--------
1000
(1 row)
QUERY: SELECT count(DISTINCT four) AS cnt_4 FROM onek;
cnt_4
-----
4
(1 row)
QUERY: select ten, count(*), sum(four) from onek group by ten;
ten|count|sum
---+-----+---
0| 100|100
1| 100|200
2| 100|100
3| 100|200
4| 100|100
5| 100|200
6| 100|100
7| 100|200
8| 100|100
9| 100|200
SELECT count(DISTINCT four) AS cnt_4 FROM onek;
cnt_4
-------
4
(1 row)
select ten, count(*), sum(four) from onek group by ten;
ten | count | sum
-----+-------+-----
0 | 100 | 100
1 | 100 | 200
2 | 100 | 100
3 | 100 | 200
4 | 100 | 100
5 | 100 | 200
6 | 100 | 100
7 | 100 | 200
8 | 100 | 100
9 | 100 | 200
(10 rows)
QUERY: select ten, count(four), sum(DISTINCT four) from onek group by ten;
ten|count|sum
---+-----+---
0| 100| 2
1| 100| 4
2| 100| 2
3| 100| 4
4| 100| 2
5| 100| 4
6| 100| 2
7| 100| 4
8| 100| 2
9| 100| 4
select ten, count(four), sum(DISTINCT four) from onek group by ten;
ten | count | sum
-----+-------+-----
0 | 100 | 2
1 | 100 | 4
2 | 100 | 2
3 | 100 | 4
4 | 100 | 2
5 | 100 | 4
6 | 100 | 2
7 | 100 | 4
8 | 100 | 2
9 | 100 | 4
(10 rows)
QUERY: SELECT newavg(four) AS avg_1 FROM onek;
avg_1
-----
1
SELECT newavg(four) AS avg_1 FROM onek;
avg_1
-------
1
(1 row)
QUERY: SELECT newsum(four) AS sum_1500 FROM onek;
sum_1500
--------
1500
SELECT newsum(four) AS sum_1500 FROM onek;
sum_1500
----------
1500
(1 row)
QUERY: SELECT newcnt(four) AS cnt_1000 FROM onek;
cnt_1000
--------
1000
SELECT newcnt(four) AS cnt_1000 FROM onek;
cnt_1000
----------
1000
(1 row)
QUERY: CREATE TABLE tmp (initial int4);
QUERY: ALTER TABLE tmp ADD COLUMN a int4;
QUERY: ALTER TABLE tmp ADD COLUMN b name;
QUERY: ALTER TABLE tmp ADD COLUMN c text;
QUERY: ALTER TABLE tmp ADD COLUMN d float8;
QUERY: ALTER TABLE tmp ADD COLUMN e float4;
QUERY: ALTER TABLE tmp ADD COLUMN f int2;
QUERY: ALTER TABLE tmp ADD COLUMN g polygon;
QUERY: ALTER TABLE tmp ADD COLUMN h abstime;
QUERY: ALTER TABLE tmp ADD COLUMN i char;
QUERY: ALTER TABLE tmp ADD COLUMN j abstime[];
QUERY: ALTER TABLE tmp ADD COLUMN k dt;
--
-- ALTER_TABLE
-- add attribute
--
CREATE TABLE tmp (initial int4);
ALTER TABLE tmp ADD COLUMN a int4;
ALTER TABLE tmp ADD COLUMN b name;
ALTER TABLE tmp ADD COLUMN c text;
ALTER TABLE tmp ADD COLUMN d float8;
ALTER TABLE tmp ADD COLUMN e float4;
ALTER TABLE tmp ADD COLUMN f int2;
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
QUERY: ALTER TABLE tmp ADD COLUMN l tid;
QUERY: ALTER TABLE tmp ADD COLUMN m xid;
QUERY: ALTER TABLE tmp ADD COLUMN n oid8;
QUERY: ALTER TABLE tmp ADD COLUMN p smgr;
QUERY: ALTER TABLE tmp ADD COLUMN q point;
QUERY: ALTER TABLE tmp ADD COLUMN r lseg;
QUERY: ALTER TABLE tmp ADD COLUMN s path;
QUERY: ALTER TABLE tmp ADD COLUMN t box;
QUERY: ALTER TABLE tmp ADD COLUMN u tinterval;
QUERY: ALTER TABLE tmp ADD COLUMN v datetime;
QUERY: ALTER TABLE tmp ADD COLUMN w timespan;
QUERY: ALTER TABLE tmp ADD COLUMN x float8[];
QUERY: ALTER TABLE tmp ADD COLUMN y float4[];
QUERY: ALTER TABLE tmp ADD COLUMN z int2[];
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 l tid;
ALTER TABLE tmp ADD COLUMN m xid;
ALTER TABLE tmp ADD COLUMN n oid8;
--ALTER TABLE tmp ADD COLUMN o lock;
ALTER TABLE tmp ADD COLUMN p smgr;
ALTER TABLE tmp ADD COLUMN q point;
ALTER TABLE tmp ADD COLUMN r lseg;
ALTER TABLE tmp ADD COLUMN s path;
ALTER TABLE tmp ADD COLUMN t box;
ALTER TABLE tmp ADD COLUMN u tinterval;
ALTER TABLE tmp ADD COLUMN v datetime;
ALTER TABLE tmp ADD COLUMN w timespan;
ALTER TABLE tmp ADD COLUMN x float8[];
ALTER TABLE tmp ADD COLUMN y float4[];
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)
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}',
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}',
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)',
'(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}');
ERROR: Relation 'tmp' does not have attribute 'k'
QUERY: 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
-------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
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
---------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
(0 rows)
QUERY: DROP TABLE tmp;
QUERY: CREATE TABLE tmp (
DROP TABLE tmp;
-- the wolf bug - schema mods caused inconsistent row descriptors
CREATE TABLE tmp (
initial int4
);
QUERY: ALTER TABLE tmp ADD COLUMN a int4;
QUERY: ALTER TABLE tmp ADD COLUMN b name;
QUERY: ALTER TABLE tmp ADD COLUMN c text;
QUERY: ALTER TABLE tmp ADD COLUMN d float8;
QUERY: ALTER TABLE tmp ADD COLUMN e float4;
QUERY: ALTER TABLE tmp ADD COLUMN f int2;
QUERY: ALTER TABLE tmp ADD COLUMN g polygon;
QUERY: ALTER TABLE tmp ADD COLUMN h abstime;
QUERY: ALTER TABLE tmp ADD COLUMN i char;
QUERY: ALTER TABLE tmp ADD COLUMN j abstime[];
QUERY: ALTER TABLE tmp ADD COLUMN k dt;
ALTER TABLE tmp ADD COLUMN a int4;
ALTER TABLE tmp ADD COLUMN b name;
ALTER TABLE tmp ADD COLUMN c text;
ALTER TABLE tmp ADD COLUMN d float8;
ALTER TABLE tmp ADD COLUMN e float4;
ALTER TABLE tmp ADD COLUMN f int2;
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
QUERY: ALTER TABLE tmp ADD COLUMN l tid;
QUERY: ALTER TABLE tmp ADD COLUMN m xid;
QUERY: ALTER TABLE tmp ADD COLUMN n oid8;
QUERY: ALTER TABLE tmp ADD COLUMN p smgr;
QUERY: ALTER TABLE tmp ADD COLUMN q point;
QUERY: ALTER TABLE tmp ADD COLUMN r lseg;
QUERY: ALTER TABLE tmp ADD COLUMN s path;
QUERY: ALTER TABLE tmp ADD COLUMN t box;
QUERY: ALTER TABLE tmp ADD COLUMN u tinterval;
QUERY: ALTER TABLE tmp ADD COLUMN v datetime;
QUERY: ALTER TABLE tmp ADD COLUMN w timespan;
QUERY: ALTER TABLE tmp ADD COLUMN x float8[];
QUERY: ALTER TABLE tmp ADD COLUMN y float4[];
QUERY: ALTER TABLE tmp ADD COLUMN z int2[];
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 l tid;
ALTER TABLE tmp ADD COLUMN m xid;
ALTER TABLE tmp ADD COLUMN n oid8;
--ALTER TABLE tmp ADD COLUMN o lock;
ALTER TABLE tmp ADD COLUMN p smgr;
ALTER TABLE tmp ADD COLUMN q point;
ALTER TABLE tmp ADD COLUMN r lseg;
ALTER TABLE tmp ADD COLUMN s path;
ALTER TABLE tmp ADD COLUMN t box;
ALTER TABLE tmp ADD COLUMN u tinterval;
ALTER TABLE tmp ADD COLUMN v datetime;
ALTER TABLE tmp ADD COLUMN w timespan;
ALTER TABLE tmp ADD COLUMN x float8[];
ALTER TABLE tmp ADD COLUMN y float4[];
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)
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}',
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)',
'(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}');
ERROR: Relation 'tmp' does not have attribute 'k'
QUERY: 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
-------+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
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
---------+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---
(0 rows)
QUERY: DROP TABLE tmp;
QUERY: ALTER TABLE tenk1 RENAME TO ten_k;
QUERY: SELECT unique1 FROM ten_k WHERE unique1 < 20;
unique1
-------
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
DROP TABLE tmp;
--
-- rename -
-- should preserve indices
--
ALTER TABLE tenk1 RENAME TO ten_k;
-- 20 values, sorted
SELECT unique1 FROM ten_k WHERE unique1 < 20;
unique1
---------
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(20 rows)
QUERY: SELECT unique2 FROM ten_k WHERE unique2 < 20;
unique2
-------
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- 20 values, sorted
SELECT unique2 FROM ten_k WHERE unique2 < 20;
unique2
---------
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(20 rows)
QUERY: 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
-- 100 values, sorted
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
(100 rows)
QUERY: ALTER TABLE ten_k RENAME TO tenk1;
QUERY: SELECT unique1 FROM tenk1 WHERE unique1 < 5;
unique1
-------
0
1
2
3
4
ALTER TABLE ten_k RENAME TO tenk1;
-- 5 values, sorted
SELECT unique1 FROM tenk1 WHERE unique1 < 5;
unique1
---------
0
1
2
3
4
(5 rows)
QUERY: SELECT b.*
--
-- BTREE_INDEX
-- test retrieval of min/max keys for each index
--
SELECT b.*
FROM bt_i4_heap b
WHERE b.seqno < 1;
seqno| random
-----+----------
0|1935401906
seqno | random
-------+------------
0 | 1935401906
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_i4_heap b
WHERE b.seqno >= 9999;
seqno| random
-----+----------
9999|1227676208
seqno | random
-------+------------
9999 | 1227676208
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_i4_heap b
WHERE b.seqno = 4500;
seqno| random
-----+----------
4500|2080851358
seqno | random
-------+------------
4500 | 2080851358
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_name_heap b
WHERE b.seqno < '1'::name;
seqno| random
-----+----------
0|1935401906
seqno | random
-------+------------
0 | 1935401906
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_name_heap b
WHERE b.seqno >= '9999'::name;
seqno| random
-----+----------
9999|1227676208
seqno | random
-------+------------
9999 | 1227676208
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_name_heap b
WHERE b.seqno = '4500'::name;
seqno| random
-----+----------
4500|2080851358
seqno | random
-------+------------
4500 | 2080851358
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_txt_heap b
WHERE b.seqno < '1'::text;
seqno| random
-----+----------
0|1935401906
seqno | random
-------+------------
0 | 1935401906
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_txt_heap b
WHERE b.seqno >= '9999'::text;
seqno| random
-----+----------
9999|1227676208
seqno | random
-------+------------
9999 | 1227676208
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_txt_heap b
WHERE b.seqno = '4500'::text;
seqno| random
-----+----------
4500|2080851358
seqno | random
-------+------------
4500 | 2080851358
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_f8_heap b
WHERE b.seqno < '1'::float8;
seqno| random
-----+----------
0|1935401906
seqno | random
-------+------------
0 | 1935401906
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_f8_heap b
WHERE b.seqno >= '9999'::float8;
seqno| random
-----+----------
9999|1227676208
seqno | random
-------+------------
9999 | 1227676208
(1 row)
QUERY: SELECT b.*
SELECT b.*
FROM bt_f8_heap b
WHERE b.seqno = '4500'::float8;
seqno| random
-----+----------
4500|2080851358
seqno | random
-------+------------
4500 | 2080851358
(1 row)
QUERY: SELECT hash_i4_heap.*
--
-- HASH_INDEX
-- grep 843938989 hash.data
--
SELECT hash_i4_heap.*
WHERE hash_i4_heap.random = 843938989;
seqno| random
-----+---------
15|843938989
seqno | random
-------+-----------
15 | 843938989
(1 row)
QUERY: SELECT hash_i4_heap.*
--
-- hash index
-- grep 66766766 hash.data
--
SELECT hash_i4_heap.*
WHERE hash_i4_heap.random = 66766766;
seqno|random
-----+------
seqno | random
-------+--------
(0 rows)
QUERY: SELECT hash_name_heap.*
--
-- hash index
-- grep 1505703298 hash.data
--
SELECT hash_name_heap.*
WHERE hash_name_heap.random = '1505703298'::name;
seqno| random
-----+----------
9838|1505703298
seqno | random
-------+------------
9838 | 1505703298
(1 row)
QUERY: SELECT hash_name_heap.*
--
-- hash index
-- grep 7777777 hash.data
--
SELECT hash_name_heap.*
WHERE hash_name_heap.random = '7777777'::name;
seqno|random
-----+------
seqno | random
-------+--------
(0 rows)
QUERY: SELECT hash_txt_heap.*
--
-- hash index
-- grep 1351610853 hash.data
--
SELECT hash_txt_heap.*
WHERE hash_txt_heap.random = '1351610853'::text;
seqno| random
-----+----------
5677|1351610853
seqno | random
-------+------------
5677 | 1351610853
(1 row)
QUERY: SELECT hash_txt_heap.*
--
-- hash index
-- grep 111111112222222233333333 hash.data
--
SELECT hash_txt_heap.*
WHERE hash_txt_heap.random = '111111112222222233333333'::text;
seqno|random
-----+------
seqno | random
-------+--------
(0 rows)
QUERY: SELECT hash_f8_heap.*
--
-- hash index
-- grep 444705537 hash.data
--
SELECT hash_f8_heap.*
WHERE hash_f8_heap.random = '444705537'::float8;
seqno| random
-----+---------
7853|444705537
seqno | random
-------+-----------
7853 | 444705537
(1 row)
QUERY: SELECT hash_f8_heap.*
--
-- hash index
-- grep 88888888 hash.data
--
SELECT hash_f8_heap.*
WHERE hash_f8_heap.random = '88888888'::float8;
seqno|random
-----+------
seqno | random
-------+--------
(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
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
WHERE h.random = 1;
i1492|i1
-----+--
1492| 1
i1492 | i1
-------+----
1492 | 1
(1 row)
QUERY: UPDATE hash_i4_heap
SET seqno = 20000
UPDATE hash_i4_heap
SET seqno = 20000
WHERE hash_i4_heap.random = 1492795354;
QUERY: SELECT h.seqno AS i20000
SELECT h.seqno AS i20000
FROM hash_i4_heap h
WHERE h.random = 1492795354;
i20000
------
20000
i20000
--------
20000
(1 row)
QUERY: UPDATE hash_name_heap
UPDATE hash_name_heap
SET random = '0123456789abcdef'::name
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
WHERE h.random = '0123456789abcdef'::name;
i6543|c0_to_f
-----+----------------
6543|0123456789abcdef
i6543 | c0_to_f
-------+------------------
6543 | 0123456789abcdef
(1 row)
QUERY: UPDATE hash_name_heap
UPDATE hash_name_heap
SET seqno = 20000
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
WHERE h.random = '76652222'::name;
emptyset
--------
emptyset
----------
(0 rows)
QUERY: UPDATE hash_txt_heap
UPDATE hash_txt_heap
SET random = '0123456789abcdefghijklmnop'::text
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
WHERE h.random = '0123456789abcdefghijklmnop'::text;
i4002|c0_to_p
-----+--------------------------
4002|0123456789abcdefghijklmnop
i4002 | c0_to_p
-------+----------------------------
4002 | 0123456789abcdefghijklmnop
(1 row)
QUERY: UPDATE hash_txt_heap
UPDATE hash_txt_heap
SET seqno = 20000
WHERE hash_txt_heap.random = '959363399'::text;
QUERY: SELECT h.seqno AS t20000
SELECT h.seqno AS t20000
FROM hash_txt_heap h
WHERE h.random = '959363399'::text;
t20000
------
20000
t20000
--------
20000
(1 row)
QUERY: UPDATE hash_f8_heap
UPDATE hash_f8_heap
SET random = '-1234.1234'::float8
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
WHERE h.random = '-1234.1234'::float8;
i8096|f1234_1234
-----+----------
8906|-1234.1234
i8096 | f1234_1234
-------+------------
8906 | -1234.1234
(1 row)
QUERY: UPDATE hash_f8_heap
UPDATE hash_f8_heap
SET seqno = 20000
WHERE hash_f8_heap.random = '488912369'::float8;
QUERY: SELECT h.seqno AS f20000
SELECT h.seqno AS f20000
FROM hash_f8_heap h
WHERE h.random = '488912369'::float8;
f20000
------
20000
f20000
--------
20000
(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,
j integer,
x text
t text
);
QUERY: CREATE TABLE JOIN2_TBL (
CREATE TABLE JOIN2_TBL (
i integer,
k integer
);
QUERY: INSERT INTO JOIN_TBL VALUES (1, 3, 'one');
QUERY: INSERT INTO JOIN_TBL VALUES (2, 2, 'two');
QUERY: INSERT INTO JOIN_TBL VALUES (3, 1, 'three');
QUERY: INSERT INTO JOIN_TBL VALUES (4, 0, 'four');
QUERY: INSERT INTO JOIN2_TBL VALUES (1, -1);
QUERY: INSERT INTO JOIN2_TBL VALUES (2, 2);
QUERY: INSERT INTO JOIN2_TBL VALUES (3, -3);
QUERY: INSERT INTO JOIN2_TBL VALUES (2, 4);
QUERY: SELECT '' AS "xxx", *
FROM JOIN_TBL CROSS JOIN JOIN2_TBL;
xxx|i|j|x |i| k
---+-+-+-----+-+--
|1|3|one |1|-1
|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
CREATE TABLE JOIN3_TBL (
i integer,
j integer,
y integer
);
CREATE TABLE JOIN4_TBL (
k integer,
z integer
);
INSERT INTO JOIN1_TBL VALUES (1, 3, 'one');
INSERT INTO JOIN1_TBL VALUES (2, 2, 'two');
INSERT INTO JOIN1_TBL VALUES (3, 1, 'three');
INSERT INTO JOIN1_TBL VALUES (4, 0, 'four');
INSERT INTO JOIN2_TBL VALUES (1, -1);
INSERT INTO JOIN2_TBL VALUES (2, 2);
INSERT INTO JOIN2_TBL VALUES (3, -3);
INSERT INTO JOIN2_TBL VALUES (2, 4);
--
-- CROSS JOIN
-- Qualifications are not allowed on cross joins,
-- which degenerate into a standard unqualified inner join.
--
SELECT '' AS "xxx", *
FROM JOIN1_TBL CROSS JOIN JOIN2_TBL;
xxx | i | j | t | i | k
-----+---+---+-------+---+----
| 1 | 3 | one | 1 | -1
| 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)
QUERY: SELECT '' AS "xxx", *
FROM JOIN_TBL NATURAL JOIN JOIN2_TBL;
SELECT '' AS "xxx", i, k, t
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
QUERY: SELECT '' AS "xxx", *
FROM JOIN_TBL INNER JOIN JOIN2_TBL USING (i);
-- Same as above, slightly different syntax
SELECT '' AS "xxx", *
FROM JOIN1_TBL JOIN JOIN2_TBL USING (i);
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
QUERY: SELECT '' AS "xxx", *
FROM JOIN_TBL JOIN JOIN2_TBL ON (JOIN_TBL.i = JOIN2_TBL.k);
SELECT '' AS "xxx", *
FROM JOIN1_TBL JOIN JOIN2_TBL ON (JOIN1_TBL.i = JOIN2_TBL.k);
ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", *
FROM JOIN_TBL CROSS JOIN JOIN2_TBL;
xxx|i|j|x |i| k
---+-+-+-----+-+--
|1|3|one |1|-1
|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
SELECT '' AS "xxx", *
FROM JOIN1_TBL CROSS JOIN JOIN2_TBL;
xxx | i | j | t | i | k
-----+---+---+-------+---+----
| 1 | 3 | one | 1 | -1
| 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)
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
QUERY: SELECT '' AS "xxx", *
FROM JOIN_TBL OUTER JOIN JOIN2_TBL USING (i);
--
-- Outer joins
--
SELECT '' AS "xxx", *
NOTICE: OUTER JOIN not yet implemented
FROM JOIN1_TBL OUTER JOIN JOIN2_TBL USING (i);
ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", *
FROM JOIN_TBL LEFT OUTER JOIN JOIN2_TBL USING (i);
SELECT '' AS "xxx", *
NOTICE: LEFT OUTER JOIN not yet implemented
FROM JOIN1_TBL LEFT OUTER JOIN JOIN2_TBL USING (i);
ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", *
FROM JOIN_TBL RIGHT OUTER JOIN JOIN2_TBL USING (i);
SELECT '' AS "xxx", *
NOTICE: RIGHT OUTER JOIN not yet implemented
FROM JOIN1_TBL RIGHT OUTER JOIN JOIN2_TBL USING (i);
ERROR: JOIN expressions are not yet implemented
QUERY: SELECT '' AS "xxx", *
FROM JOIN_TBL FULL OUTER JOIN JOIN2_TBL USING (i);
SELECT '' AS "xxx", *
NOTICE: FULL OUTER JOIN not yet implemented
FROM JOIN1_TBL FULL OUTER JOIN JOIN2_TBL USING (i);
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;
two|unique1|unique2|stringu1
---+-------+-------+--------
| 51| 76|ZBAAAA
| 52| 985|ACAAAA
two | unique1 | unique2 | stringu1
-----+---------+---------+----------
| 51 | 76 | ZBAAAA
| 52 | 985 | ACAAAA
(2 rows)
QUERY: SELECT ''::text AS five, unique1, unique2, stringu1
FROM onek WHERE unique1 > 60
SELECT ''::text AS five, unique1, unique2, stringu1
FROM onek WHERE unique1 > 60
ORDER BY unique1 LIMIT 5;
five|unique1|unique2|stringu1
----+-------+-------+--------
| 61| 560|JCAAAA
| 62| 633|KCAAAA
| 63| 296|LCAAAA
| 64| 479|MCAAAA
| 65| 64|NCAAAA
five | unique1 | unique2 | stringu1
------+---------+---------+----------
| 61 | 560 | JCAAAA
| 62 | 633 | KCAAAA
| 63 | 296 | LCAAAA
| 64 | 479 | MCAAAA
| 65 | 64 | NCAAAA
(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
ORDER BY unique1 LIMIT 5;
two|unique1|unique2|stringu1
---+-------+-------+--------
| 61| 560|JCAAAA
| 62| 633|KCAAAA
two | unique1 | unique2 | stringu1
-----+---------+---------+----------
| 61 | 560 | JCAAAA
| 62 | 633 | KCAAAA
(2 rows)
QUERY: SELECT ''::text AS three, unique1, unique2, stringu1
FROM onek WHERE unique1 > 100
SELECT ''::text AS three, unique1, unique2, stringu1
FROM onek WHERE unique1 > 100
ORDER BY unique1 LIMIT 3 OFFSET 20;
three|unique1|unique2|stringu1
-----+-------+-------+--------
| 121| 700|REAAAA
| 122| 519|SEAAAA
| 123| 777|TEAAAA
three | unique1 | unique2 | stringu1
-------+---------+---------+----------
| 121 | 700 | REAAAA
| 122 | 519 | SEAAAA
| 123 | 777 | TEAAAA
(3 rows)
QUERY: SELECT ''::text AS zero, unique1, unique2, stringu1
FROM onek WHERE unique1 < 50
SELECT ''::text AS zero, unique1, unique2, stringu1
FROM onek WHERE unique1 < 50
ORDER BY unique1 DESC LIMIT 8 OFFSET 99;
zero|unique1|unique2|stringu1
----+-------+-------+--------
zero | unique1 | unique2 | stringu1
------+---------+---------+----------
(0 rows)
QUERY: SELECT ''::text AS eleven, unique1, unique2, stringu1
FROM onek WHERE unique1 < 50
SELECT ''::text AS eleven, unique1, unique2, stringu1
FROM onek WHERE unique1 < 50
ORDER BY unique1 DESC LIMIT 20 OFFSET 39;
eleven|unique1|unique2|stringu1
------+-------+-------+--------
| 10| 520|KAAAAA
| 9| 49|JAAAAA
| 8| 653|IAAAAA
| 7| 647|HAAAAA
| 6| 978|GAAAAA
| 5| 541|FAAAAA
| 4| 833|EAAAAA
| 3| 431|DAAAAA
| 2| 326|CAAAAA
| 1| 214|BAAAAA
| 0| 998|AAAAAA
eleven | unique1 | unique2 | stringu1
--------+---------+---------+----------
| 10 | 520 | KAAAAA
| 9 | 49 | JAAAAA
| 8 | 653 | IAAAAA
| 7 | 647 | HAAAAA
| 6 | 978 | GAAAAA
| 5 | 541 | FAAAAA
| 4 | 833 | EAAAAA
| 3 | 431 | DAAAAA
| 2 | 326 | CAAAAA
| 1 | 214 | BAAAAA
| 0 | 998 | AAAAAA
(11 rows)
QUERY: SELECT ''::text AS ten, unique1, unique2, stringu1
SELECT ''::text AS ten, unique1, unique2, stringu1
FROM onek
ORDER BY unique1 OFFSET 990;
ten|unique1|unique2|stringu1
---+-------+-------+--------
| 990| 369|CMAAAA
| 991| 426|DMAAAA
| 992| 363|EMAAAA
| 993| 661|FMAAAA
| 994| 695|GMAAAA
| 995| 144|HMAAAA
| 996| 258|IMAAAA
| 997| 21|JMAAAA
| 998| 549|KMAAAA
| 999| 152|LMAAAA
ten | unique1 | unique2 | stringu1
-----+---------+---------+----------
| 990 | 369 | CMAAAA
| 991 | 426 | DMAAAA
| 992 | 363 | EMAAAA
| 993 | 661 | FMAAAA
| 994 | 695 | GMAAAA
| 995 | 144 | HMAAAA
| 996 | 258 | IMAAAA
| 997 | 21 | JMAAAA
| 998 | 549 | KMAAAA
| 999 | 152 | LMAAAA
(10 rows)
QUERY: SELECT ''::text AS five, unique1, unique2, stringu1
SELECT ''::text AS five, unique1, unique2, stringu1
FROM onek
ORDER BY unique1 OFFSET 990 LIMIT 5;
five|unique1|unique2|stringu1
----+-------+-------+--------
| 990| 369|CMAAAA
| 991| 426|DMAAAA
| 992| 363|EMAAAA
| 993| 661|FMAAAA
| 994| 695|GMAAAA
five | unique1 | unique2 | stringu1
------+---------+---------+----------
| 990 | 369 | CMAAAA
| 991 | 426 | DMAAAA
| 992 | 363 | EMAAAA
| 993 | 661 | FMAAAA
| 994 | 695 | GMAAAA
(5 rows)
QUERY: SELECT ''::text AS five, unique1, unique2, stringu1
SELECT ''::text AS five, unique1, unique2, stringu1
FROM onek
ORDER BY unique1 LIMIT 5, 900;
five|unique1|unique2|stringu1
----+-------+-------+--------
| 900| 913|QIAAAA
| 901| 931|RIAAAA
| 902| 702|SIAAAA
| 903| 641|TIAAAA
| 904| 793|UIAAAA
five | unique1 | unique2 | stringu1
------+---------+---------+----------
| 900 | 913 | QIAAAA
| 901 | 931 | RIAAAA
| 902 | 702 | SIAAAA
| 903 | 641 | TIAAAA
| 904 | 793 | UIAAAA
(5 rows)
QUERY: create table Room (
--
-- PLPGSQL
--
create table Room (
roomno char(8),
comment text
);
QUERY: create unique index Room_rno on Room using btree (roomno bpchar_ops);
QUERY: create table WSlot (
create unique index Room_rno on Room using btree (roomno bpchar_ops);
create table WSlot (
slotname char(20),
roomno char(8),
slotlink char(20),
backlink char(20)
);
QUERY: create unique index WSlot_name on WSlot using btree (slotname bpchar_ops);
QUERY: create table PField (
create unique index WSlot_name on WSlot using btree (slotname bpchar_ops);
create table PField (
name text,
comment text
);
QUERY: create unique index PField_name on PField using btree (name text_ops);
QUERY: create table PSlot (
create unique index PField_name on PField using btree (name text_ops);
create table PSlot (
slotname char(20),
pfname text,
slotlink char(20),
backlink char(20)
);
QUERY: create unique index PSlot_name on PSlot using btree (slotname bpchar_ops);
QUERY: create table PLine (
create unique index PSlot_name on PSlot using btree (slotname bpchar_ops);
create table PLine (
slotname char(20),
phonenumber char(20),
comment text,
backlink char(20)
);
QUERY: create unique index PLine_name on PLine using btree (slotname bpchar_ops);
QUERY: create table Hub (
create unique index PLine_name on PLine using btree (slotname bpchar_ops);
create table Hub (
name char(14),
comment text,
nslots integer
);
QUERY: create unique index Hub_name on Hub using btree (name bpchar_ops);
QUERY: create table HSlot (
create unique index Hub_name on Hub using btree (name bpchar_ops);
create table HSlot (
slotname char(20),
hubname char(14),
slotno integer,
slotlink char(20)
);
QUERY: create unique index HSlot_name on HSlot using btree (slotname bpchar_ops);
QUERY: create index HSlot_hubname on HSlot using btree (hubname bpchar_ops);
QUERY: create table System (
create unique index HSlot_name on HSlot using btree (slotname bpchar_ops);
create index HSlot_hubname on HSlot using btree (hubname bpchar_ops);
create table System (
name text,
comment text
);
QUERY: create unique index System_name on System using btree (name text_ops);
QUERY: create table IFace (
create unique index System_name on System using btree (name text_ops);
create table IFace (
slotname char(20),
sysname text,
ifname text,
slotlink char(20)
);
QUERY: create unique index IFace_name on IFace using btree (slotname bpchar_ops);
QUERY: create table PHone (
create unique index IFace_name on IFace using btree (slotname bpchar_ops);
create table PHone (
slotname char(20),
comment text,
slotlink char(20)
);
QUERY: create unique index PHone_name on PHone using btree (slotname bpchar_ops);
QUERY: create function tg_room_au() returns opaque as '
create unique index PHone_name on PHone using btree (slotname bpchar_ops);
-- ************************************************************
-- *
-- * 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
if new.roomno != old.roomno then
update WSlot set roomno = new.roomno where roomno = old.roomno;
......@@ -69,17 +84,25 @@ begin
return new;
end;
' 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();
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
delete from WSlot where roomno = old.roomno;
return old;
end;
' 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();
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
if count(*) = 0 from Room where roomno = new.roomno then
raise exception ''Room % does not exist'', new.roomno;
......@@ -87,9 +110,13 @@ begin
return new;
end;
' 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();
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
if new.name != old.name then
update PSlot set pfname = new.name where pfname = old.name;
......@@ -97,17 +124,25 @@ begin
return new;
end;
' 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();
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
delete from PSlot where pfname = old.name;
return old;
end;
' 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();
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
pfrec record;
rename new to ps;
......@@ -119,9 +154,13 @@ begin
return ps;
end;
' 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();
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
if new.name != old.name then
update IFace set sysname = new.name where sysname = old.name;
......@@ -129,9 +168,13 @@ begin
return new;
end;
' 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();
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
sname text;
sysrec record;
......@@ -150,9 +193,13 @@ begin
return new;
end;
' 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();
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
hname text;
dummy integer;
......@@ -174,9 +221,12 @@ begin
end if;
end;
' 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();
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 '
declare
hname alias for $1;
......@@ -197,7 +247,12 @@ begin
return 0;
end;
' 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
sname text;
xname HSlot.slotname%TYPE;
......@@ -227,9 +282,13 @@ begin
return new;
end;
' 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();
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
hubrec record;
begin
......@@ -243,9 +302,13 @@ begin
raise exception ''no manual manipulation of HSlot'';
end;
' 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();
QUERY: create function tg_chkslotname() returns opaque as '
-- ************************************************************
-- * BEFORE INSERT on all slots
-- * - Check name prefix
-- ************************************************************
create function tg_chkslotname() returns opaque as '
begin
if substr(new.slotname, 1, 2) != tg_argv[0] then
raise exception ''slotname must begin with %'', tg_argv[0];
......@@ -253,17 +316,21 @@ begin
return new;
end;
' 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');
QUERY: create trigger tg_chkslotname before insert
create trigger tg_chkslotname before insert
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');
QUERY: create trigger tg_chkslotname before insert
create trigger tg_chkslotname before insert
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');
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
if new.slotlink isnull then
new.slotlink := '''';
......@@ -271,17 +338,21 @@ begin
return new;
end;
' 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();
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();
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();
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();
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();
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
if new.backlink isnull then
new.backlink := '''';
......@@ -289,13 +360,17 @@ begin
return new;
end;
' 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();
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();
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();
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
if new.slotname != old.slotname then
delete from PSlot where slotname = old.slotname;
......@@ -315,9 +390,13 @@ begin
return new;
end;
' 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();
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
if new.slotname != old.slotname then
delete from WSlot where slotname = old.slotname;
......@@ -337,9 +416,13 @@ begin
return new;
end;
' 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();
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
if new.slotname != old.slotname then
delete from PLine where slotname = old.slotname;
......@@ -359,9 +442,13 @@ begin
return new;
end;
' 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();
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
if new.slotname != old.slotname then
delete from IFace where slotname = old.slotname;
......@@ -381,9 +468,13 @@ begin
return new;
end;
' 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();
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
if new.slotname != old.slotname or new.hubname != old.hubname then
delete from HSlot where slotname = old.slotname;
......@@ -403,9 +494,13 @@ begin
return new;
end;
' 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();
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
if new.slotname != old.slotname then
delete from PHone where slotname = old.slotname;
......@@ -423,9 +518,13 @@ begin
return new;
end;
' 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();
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
dummy integer;
begin
......@@ -458,13 +557,17 @@ begin
end if;
end;
' 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');
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');
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');
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 '
declare
myname alias for $1;
......@@ -476,11 +579,11 @@ begin
mytype := substr(myname, 1, 2);
link := mytype || substr(blname, 1, 2);
if link = ''PLPL'' then
raise exception
raise exception
''backlink between two phone lines does not make sense'';
end if;
if link in (''PLWS'', ''WSPL'') then
raise exception
raise exception
''direct link of phone line to wall slot not permitted'';
end if;
if mytype = ''PS'' then
......@@ -516,7 +619,11 @@ begin
raise exception ''illegal backlink beginning with %'', mytype;
end;
' 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 '
declare
myname alias for $1;
......@@ -557,7 +664,11 @@ begin
end if;
end;
' 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
dummy integer;
begin
......@@ -590,17 +701,21 @@ begin
end if;
end;
' 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');
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');
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');
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');
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');
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 '
declare
myname alias for $1;
......@@ -612,19 +727,19 @@ begin
mytype := substr(myname, 1, 2);
link := mytype || substr(blname, 1, 2);
if link = ''PHPH'' then
raise exception
raise exception
''slotlink between two phones does not make sense'';
end if;
if link in (''PHHS'', ''HSPH'') then
raise exception
raise exception
''link of phone to hub does not make sense'';
end if;
if link in (''PHIF'', ''IFPH'') then
raise exception
raise exception
''link of phone to hub does not make sense'';
end if;
if link in (''PSWS'', ''WSPS'') then
raise exception
raise exception
''slotlink from patchslot to wallslot not permitted'';
end if;
if mytype = ''PS'' then
......@@ -680,7 +795,11 @@ begin
raise exception ''illegal slotlink beginning with %'', mytype;
end;
' 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 '
declare
myname alias for $1;
......@@ -741,7 +860,10 @@ begin
end if;
end;
' 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 '
<<outer>>
declare
......@@ -781,7 +903,10 @@ begin
return rec.backlink;
end;
' 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 '
declare
psrec record;
......@@ -812,7 +937,10 @@ begin
return psrec.slotlink;
end;
' 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 '
declare
rec record;
......@@ -857,480 +985,535 @@ begin
return rec.slotlink;
end;
' 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_slotlink_view(PF.slotname) as patch
from PSlot PF;
QUERY: insert into Room values ('001', 'Entrance');
QUERY: insert into Room values ('002', 'Office');
QUERY: insert into Room values ('003', 'Office');
QUERY: insert into Room values ('004', 'Technical');
QUERY: insert into Room values ('101', 'Office');
QUERY: insert into Room values ('102', 'Conference');
QUERY: insert into Room values ('103', 'Restroom');
QUERY: insert into Room values ('104', 'Technical');
QUERY: insert into Room values ('105', 'Office');
QUERY: insert into Room values ('106', 'Office');
QUERY: insert into WSlot values ('WS.001.1a', '001', '', '');
QUERY: insert into WSlot values ('WS.001.1b', '001', '', '');
QUERY: insert into WSlot values ('WS.001.2a', '001', '', '');
QUERY: insert into WSlot values ('WS.001.2b', '001', '', '');
QUERY: insert into WSlot values ('WS.001.3a', '001', '', '');
QUERY: insert into WSlot values ('WS.001.3b', '001', '', '');
QUERY: insert into WSlot values ('WS.002.1a', '002', '', '');
QUERY: insert into WSlot values ('WS.002.1b', '002', '', '');
QUERY: insert into WSlot values ('WS.002.2a', '002', '', '');
QUERY: insert into WSlot values ('WS.002.2b', '002', '', '');
QUERY: insert into WSlot values ('WS.002.3a', '002', '', '');
QUERY: insert into WSlot values ('WS.002.3b', '002', '', '');
QUERY: insert into WSlot values ('WS.003.1a', '003', '', '');
QUERY: insert into WSlot values ('WS.003.1b', '003', '', '');
QUERY: insert into WSlot values ('WS.003.2a', '003', '', '');
QUERY: insert into WSlot values ('WS.003.2b', '003', '', '');
QUERY: insert into WSlot values ('WS.003.3a', '003', '', '');
QUERY: insert into WSlot values ('WS.003.3b', '003', '', '');
QUERY: insert into WSlot values ('WS.101.1a', '101', '', '');
QUERY: insert into WSlot values ('WS.101.1b', '101', '', '');
QUERY: insert into WSlot values ('WS.101.2a', '101', '', '');
QUERY: insert into WSlot values ('WS.101.2b', '101', '', '');
QUERY: insert into WSlot values ('WS.101.3a', '101', '', '');
QUERY: insert into WSlot values ('WS.101.3b', '101', '', '');
QUERY: insert into WSlot values ('WS.102.1a', '102', '', '');
QUERY: insert into WSlot values ('WS.102.1b', '102', '', '');
QUERY: insert into WSlot values ('WS.102.2a', '102', '', '');
QUERY: insert into WSlot values ('WS.102.2b', '102', '', '');
QUERY: insert into WSlot values ('WS.102.3a', '102', '', '');
QUERY: insert into WSlot values ('WS.102.3b', '102', '', '');
QUERY: insert into WSlot values ('WS.105.1a', '105', '', '');
QUERY: insert into WSlot values ('WS.105.1b', '105', '', '');
QUERY: insert into WSlot values ('WS.105.2a', '105', '', '');
QUERY: insert into WSlot values ('WS.105.2b', '105', '', '');
QUERY: insert into WSlot values ('WS.105.3a', '105', '', '');
QUERY: insert into WSlot values ('WS.105.3b', '105', '', '');
QUERY: insert into WSlot values ('WS.106.1a', '106', '', '');
QUERY: insert into WSlot values ('WS.106.1b', '106', '', '');
QUERY: insert into WSlot values ('WS.106.2a', '106', '', '');
QUERY: insert into WSlot values ('WS.106.2b', '106', '', '');
QUERY: insert into WSlot values ('WS.106.3a', '106', '', '');
QUERY: insert into WSlot values ('WS.106.3b', '106', '', '');
QUERY: insert into PField values ('PF0_1', 'Wallslots basement');
QUERY: insert into PSlot values ('PS.base.a1', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.a2', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.a3', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.a4', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.a5', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.a6', 'PF0_1', '', '');
QUERY: insert into PSlot values ('PS.base.b1', 'PF0_1', '', 'WS.002.1a');
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');
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');
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');
QUERY: insert into PSlot values ('PS.base.c2', 'PF0_1', '', 'WS.003.1b');
QUERY: insert into PSlot values ('PS.base.c3', 'PF0_1', '', 'WS.003.2a');
QUERY: insert into PSlot values ('PS.base.c4', 'PF0_1', '', 'WS.003.2b');
QUERY: insert into PSlot values ('PS.base.c5', 'PF0_1', '', 'WS.003.3a');
QUERY: insert into PSlot values ('PS.base.c6', 'PF0_1', '', 'WS.003.3b');
QUERY: insert into PField values ('PF0_X', 'Phonelines basement');
QUERY: insert into PSlot values ('PS.base.ta1', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.ta2', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.ta3', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.ta4', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.ta5', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.ta6', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.tb1', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.tb2', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.tb3', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.tb4', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.tb5', 'PF0_X', '', '');
QUERY: insert into PSlot values ('PS.base.tb6', 'PF0_X', '', '');
QUERY: insert into PField values ('PF1_1', 'Wallslots 1st floor');
QUERY: insert into PSlot values ('PS.1st.a1', 'PF1_1', '', 'WS.101.1a');
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');
QUERY: insert into PSlot values ('PS.1st.a4', 'PF1_1', '', 'WS.101.2b');
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');
QUERY: insert into PSlot values ('PS.1st.b1', 'PF1_1', '', 'WS.102.1a');
QUERY: insert into PSlot values ('PS.1st.b2', 'PF1_1', '', 'WS.102.1b');
QUERY: insert into PSlot values ('PS.1st.b3', 'PF1_1', '', 'WS.102.2a');
QUERY: insert into PSlot values ('PS.1st.b4', 'PF1_1', '', 'WS.102.2b');
QUERY: insert into PSlot values ('PS.1st.b5', 'PF1_1', '', 'WS.102.3a');
QUERY: insert into PSlot values ('PS.1st.b6', 'PF1_1', '', 'WS.102.3b');
QUERY: insert into PSlot values ('PS.1st.c1', 'PF1_1', '', 'WS.105.1a');
QUERY: insert into PSlot values ('PS.1st.c2', 'PF1_1', '', 'WS.105.1b');
QUERY: insert into PSlot values ('PS.1st.c3', 'PF1_1', '', 'WS.105.2a');
QUERY: insert into PSlot values ('PS.1st.c4', 'PF1_1', '', 'WS.105.2b');
QUERY: insert into PSlot values ('PS.1st.c5', 'PF1_1', '', 'WS.105.3a');
QUERY: insert into PSlot values ('PS.1st.c6', 'PF1_1', '', 'WS.105.3b');
QUERY: insert into PSlot values ('PS.1st.d1', 'PF1_1', '', 'WS.106.1a');
QUERY: insert into PSlot values ('PS.1st.d2', 'PF1_1', '', 'WS.106.1b');
QUERY: insert into PSlot values ('PS.1st.d3', 'PF1_1', '', 'WS.106.2a');
QUERY: insert into PSlot values ('PS.1st.d4', 'PF1_1', '', 'WS.106.2b');
QUERY: insert into PSlot values ('PS.1st.d5', 'PF1_1', '', 'WS.106.3a');
QUERY: insert into PSlot values ('PS.1st.d6', 'PF1_1', '', 'WS.106.3b');
QUERY: update PSlot set backlink = 'WS.001.1a' where slotname = 'PS.base.a1';
QUERY: update PSlot set backlink = 'WS.001.1b' where slotname = 'PS.base.a3';
QUERY: 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 | |
--
-- First we build the house - so we create the rooms
--
insert into Room values ('001', 'Entrance');
insert into Room values ('002', 'Office');
insert into Room values ('003', 'Office');
insert into Room values ('004', 'Technical');
insert into Room values ('101', 'Office');
insert into Room values ('102', 'Conference');
insert into Room values ('103', 'Restroom');
insert into Room values ('104', 'Technical');
insert into Room values ('105', 'Office');
insert into Room values ('106', 'Office');
--
-- Second we install the wall connectors
--
insert into WSlot values ('WS.001.1a', '001', '', '');
insert into WSlot values ('WS.001.1b', '001', '', '');
insert into WSlot values ('WS.001.2a', '001', '', '');
insert into WSlot values ('WS.001.2b', '001', '', '');
insert into WSlot values ('WS.001.3a', '001', '', '');
insert into WSlot values ('WS.001.3b', '001', '', '');
insert into WSlot values ('WS.002.1a', '002', '', '');
insert into WSlot values ('WS.002.1b', '002', '', '');
insert into WSlot values ('WS.002.2a', '002', '', '');
insert into WSlot values ('WS.002.2b', '002', '', '');
insert into WSlot values ('WS.002.3a', '002', '', '');
insert into WSlot values ('WS.002.3b', '002', '', '');
insert into WSlot values ('WS.003.1a', '003', '', '');
insert into WSlot values ('WS.003.1b', '003', '', '');
insert into WSlot values ('WS.003.2a', '003', '', '');
insert into WSlot values ('WS.003.2b', '003', '', '');
insert into WSlot values ('WS.003.3a', '003', '', '');
insert into WSlot values ('WS.003.3b', '003', '', '');
insert into WSlot values ('WS.101.1a', '101', '', '');
insert into WSlot values ('WS.101.1b', '101', '', '');
insert into WSlot values ('WS.101.2a', '101', '', '');
insert into WSlot values ('WS.101.2b', '101', '', '');
insert into WSlot values ('WS.101.3a', '101', '', '');
insert into WSlot values ('WS.101.3b', '101', '', '');
insert into WSlot values ('WS.102.1a', '102', '', '');
insert into WSlot values ('WS.102.1b', '102', '', '');
insert into WSlot values ('WS.102.2a', '102', '', '');
insert into WSlot values ('WS.102.2b', '102', '', '');
insert into WSlot values ('WS.102.3a', '102', '', '');
insert into WSlot values ('WS.102.3b', '102', '', '');
insert into WSlot values ('WS.105.1a', '105', '', '');
insert into WSlot values ('WS.105.1b', '105', '', '');
insert into WSlot values ('WS.105.2a', '105', '', '');
insert into WSlot values ('WS.105.2b', '105', '', '');
insert into WSlot values ('WS.105.3a', '105', '', '');
insert into WSlot values ('WS.105.3b', '105', '', '');
insert into WSlot values ('WS.106.1a', '106', '', '');
insert into WSlot values ('WS.106.1b', '106', '', '');
insert into WSlot values ('WS.106.2a', '106', '', '');
insert into WSlot values ('WS.106.2b', '106', '', '');
insert into WSlot values ('WS.106.3a', '106', '', '');
insert into WSlot values ('WS.106.3b', '106', '', '');
--
-- Now create the patch fields and their slots
--
insert into PField values ('PF0_1', 'Wallslots basement');
--
-- The cables for these will be made later, so they are unconnected for now
--
insert into PSlot values ('PS.base.a1', 'PF0_1', '', '');
insert into PSlot values ('PS.base.a2', 'PF0_1', '', '');
insert into PSlot values ('PS.base.a3', 'PF0_1', '', '');
insert into PSlot values ('PS.base.a4', 'PF0_1', '', '');
insert into PSlot values ('PS.base.a5', 'PF0_1', '', '');
insert into PSlot values ('PS.base.a6', 'PF0_1', '', '');
--
-- These are already wired to the wall connectors
--
insert into PSlot values ('PS.base.b1', 'PF0_1', '', 'WS.002.1a');
insert into PSlot values ('PS.base.b2', 'PF0_1', '', 'WS.002.1b');
insert into PSlot values ('PS.base.b3', 'PF0_1', '', 'WS.002.2a');
insert into PSlot values ('PS.base.b4', 'PF0_1', '', 'WS.002.2b');
insert into PSlot values ('PS.base.b5', 'PF0_1', '', 'WS.002.3a');
insert into PSlot values ('PS.base.b6', 'PF0_1', '', 'WS.002.3b');
insert into PSlot values ('PS.base.c1', 'PF0_1', '', 'WS.003.1a');
insert into PSlot values ('PS.base.c2', 'PF0_1', '', 'WS.003.1b');
insert into PSlot values ('PS.base.c3', 'PF0_1', '', 'WS.003.2a');
insert into PSlot values ('PS.base.c4', 'PF0_1', '', 'WS.003.2b');
insert into PSlot values ('PS.base.c5', 'PF0_1', '', 'WS.003.3a');
insert into PSlot values ('PS.base.c6', 'PF0_1', '', 'WS.003.3b');
--
-- This patchfield will be renamed later into PF0_2 - so its
-- slots references in pfname should follow
--
insert into PField values ('PF0_X', 'Phonelines basement');
insert into PSlot values ('PS.base.ta1', 'PF0_X', '', '');
insert into PSlot values ('PS.base.ta2', 'PF0_X', '', '');
insert into PSlot values ('PS.base.ta3', 'PF0_X', '', '');
insert into PSlot values ('PS.base.ta4', 'PF0_X', '', '');
insert into PSlot values ('PS.base.ta5', 'PF0_X', '', '');
insert into PSlot values ('PS.base.ta6', 'PF0_X', '', '');
insert into PSlot values ('PS.base.tb1', 'PF0_X', '', '');
insert into PSlot values ('PS.base.tb2', 'PF0_X', '', '');
insert into PSlot values ('PS.base.tb3', 'PF0_X', '', '');
insert into PSlot values ('PS.base.tb4', 'PF0_X', '', '');
insert into PSlot values ('PS.base.tb5', 'PF0_X', '', '');
insert into PSlot values ('PS.base.tb6', 'PF0_X', '', '');
insert into PField values ('PF1_1', 'Wallslots 1st floor');
insert into PSlot values ('PS.1st.a1', 'PF1_1', '', 'WS.101.1a');
insert into PSlot values ('PS.1st.a2', 'PF1_1', '', 'WS.101.1b');
insert into PSlot values ('PS.1st.a3', 'PF1_1', '', 'WS.101.2a');
insert into PSlot values ('PS.1st.a4', 'PF1_1', '', 'WS.101.2b');
insert into PSlot values ('PS.1st.a5', 'PF1_1', '', 'WS.101.3a');
insert into PSlot values ('PS.1st.a6', 'PF1_1', '', 'WS.101.3b');
insert into PSlot values ('PS.1st.b1', 'PF1_1', '', 'WS.102.1a');
insert into PSlot values ('PS.1st.b2', 'PF1_1', '', 'WS.102.1b');
insert into PSlot values ('PS.1st.b3', 'PF1_1', '', 'WS.102.2a');
insert into PSlot values ('PS.1st.b4', 'PF1_1', '', 'WS.102.2b');
insert into PSlot values ('PS.1st.b5', 'PF1_1', '', 'WS.102.3a');
insert into PSlot values ('PS.1st.b6', 'PF1_1', '', 'WS.102.3b');
insert into PSlot values ('PS.1st.c1', 'PF1_1', '', 'WS.105.1a');
insert into PSlot values ('PS.1st.c2', 'PF1_1', '', 'WS.105.1b');
insert into PSlot values ('PS.1st.c3', 'PF1_1', '', 'WS.105.2a');
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)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink
--------------------+------+--------------------+--------------------
PS.base.a1 |PF0_1 | |WS.001.1a
PS.base.a2 |PF0_1 | |
PS.base.a3 |PF0_1 | |WS.001.1b
PS.base.a4 |PF0_1 | |
PS.base.a5 |PF0_1 | |
PS.base.a6 |PF0_1 | |
select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname | pfname | slotlink | backlink
----------------------+--------+----------------------+----------------------
PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 | PF0_1 | |
PS.base.a3 | PF0_1 | | WS.001.1b
PS.base.a4 | PF0_1 | |
PS.base.a5 | PF0_1 | |
PS.base.a6 | PF0_1 | |
(6 rows)
QUERY: update PSlot set backlink = 'WS.001.2a' where slotname = 'PS.base.a3';
QUERY: select * from WSlot where roomno = '001' order by slotname;
slotname |roomno |slotlink |backlink
--------------------+--------+--------------------+--------------------
WS.001.1a |001 | |PS.base.a1
WS.001.1b |001 | |
WS.001.2a |001 | |PS.base.a3
WS.001.2b |001 | |
WS.001.3a |001 | |
WS.001.3b |001 | |
update PSlot set backlink = 'WS.001.2a' 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 | |
WS.001.2a | 001 | | PS.base.a3
WS.001.2b | 001 | |
WS.001.3a | 001 | |
WS.001.3b | 001 | |
(6 rows)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink
--------------------+------+--------------------+--------------------
PS.base.a1 |PF0_1 | |WS.001.1a
PS.base.a2 |PF0_1 | |
PS.base.a3 |PF0_1 | |WS.001.2a
PS.base.a4 |PF0_1 | |
PS.base.a5 |PF0_1 | |
PS.base.a6 |PF0_1 | |
select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname | pfname | slotlink | backlink
----------------------+--------+----------------------+----------------------
PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 | PF0_1 | |
PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 | PF0_1 | |
PS.base.a5 | PF0_1 | |
PS.base.a6 | PF0_1 | |
(6 rows)
QUERY: update PSlot set backlink = 'WS.001.1b' where slotname = 'PS.base.a2';
QUERY: 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.a2
WS.001.2a |001 | |PS.base.a3
WS.001.2b |001 | |
WS.001.3a |001 | |
WS.001.3b |001 | |
update PSlot set backlink = 'WS.001.1b' where slotname = 'PS.base.a2';
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.a2
WS.001.2a | 001 | | PS.base.a3
WS.001.2b | 001 | |
WS.001.3a | 001 | |
WS.001.3b | 001 | |
(6 rows)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink
--------------------+------+--------------------+--------------------
PS.base.a1 |PF0_1 | |WS.001.1a
PS.base.a2 |PF0_1 | |WS.001.1b
PS.base.a3 |PF0_1 | |WS.001.2a
PS.base.a4 |PF0_1 | |
PS.base.a5 |PF0_1 | |
PS.base.a6 |PF0_1 | |
select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname | pfname | slotlink | backlink
----------------------+--------+----------------------+----------------------
PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 | PF0_1 | | WS.001.1b
PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 | PF0_1 | |
PS.base.a5 | PF0_1 | |
PS.base.a6 | PF0_1 | |
(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';
QUERY: 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.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 | |
--
-- Same procedure for 2b-3b but this time updating the WSlot instead
-- of the PSlot. Due to the triggers the result is the same:
-- WSlot and corresponding PSlot point to each other.
--
update WSlot set backlink = 'PS.base.a4' where slotname = 'WS.001.2b';
update WSlot set backlink = 'PS.base.a6' where slotname = 'WS.001.3a';
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.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)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink
--------------------+------+--------------------+--------------------
PS.base.a1 |PF0_1 | |WS.001.1a
PS.base.a2 |PF0_1 | |WS.001.1b
PS.base.a3 |PF0_1 | |WS.001.2a
PS.base.a4 |PF0_1 | |WS.001.2b
PS.base.a5 |PF0_1 | |
PS.base.a6 |PF0_1 | |WS.001.3a
select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname | pfname | slotlink | backlink
----------------------+--------+----------------------+----------------------
PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 | PF0_1 | | WS.001.1b
PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 | PF0_1 | | WS.001.2b
PS.base.a5 | PF0_1 | |
PS.base.a6 | PF0_1 | | WS.001.3a
(6 rows)
QUERY: update WSlot set backlink = 'PS.base.a6' where slotname = 'WS.001.3b';
QUERY: 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.a2
WS.001.2a |001 | |PS.base.a3
WS.001.2b |001 | |PS.base.a4
WS.001.3a |001 | |
WS.001.3b |001 | |PS.base.a6
update WSlot set backlink = 'PS.base.a6' where slotname = 'WS.001.3b';
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.a2
WS.001.2a | 001 | | PS.base.a3
WS.001.2b | 001 | | PS.base.a4
WS.001.3a | 001 | |
WS.001.3b | 001 | | PS.base.a6
(6 rows)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink
--------------------+------+--------------------+--------------------
PS.base.a1 |PF0_1 | |WS.001.1a
PS.base.a2 |PF0_1 | |WS.001.1b
PS.base.a3 |PF0_1 | |WS.001.2a
PS.base.a4 |PF0_1 | |WS.001.2b
PS.base.a5 |PF0_1 | |
PS.base.a6 |PF0_1 | |WS.001.3b
select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname | pfname | slotlink | backlink
----------------------+--------+----------------------+----------------------
PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 | PF0_1 | | WS.001.1b
PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 | PF0_1 | | WS.001.2b
PS.base.a5 | PF0_1 | |
PS.base.a6 | PF0_1 | | WS.001.3b
(6 rows)
QUERY: update WSlot set backlink = 'PS.base.a5' where slotname = 'WS.001.3a';
QUERY: 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.a2
WS.001.2a |001 | |PS.base.a3
WS.001.2b |001 | |PS.base.a4
WS.001.3a |001 | |PS.base.a5
WS.001.3b |001 | |PS.base.a6
update WSlot set backlink = 'PS.base.a5' where slotname = 'WS.001.3a';
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.a2
WS.001.2a | 001 | | PS.base.a3
WS.001.2b | 001 | | PS.base.a4
WS.001.3a | 001 | | PS.base.a5
WS.001.3b | 001 | | PS.base.a6
(6 rows)
QUERY: select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname |pfname|slotlink |backlink
--------------------+------+--------------------+--------------------
PS.base.a1 |PF0_1 | |WS.001.1a
PS.base.a2 |PF0_1 | |WS.001.1b
PS.base.a3 |PF0_1 | |WS.001.2a
PS.base.a4 |PF0_1 | |WS.001.2b
PS.base.a5 |PF0_1 | |WS.001.3a
PS.base.a6 |PF0_1 | |WS.001.3b
select * from PSlot where slotname ~ 'PS.base.a' order by slotname;
slotname | pfname | slotlink | backlink
----------------------+--------+----------------------+----------------------
PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 | PF0_1 | | WS.001.1b
PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 | PF0_1 | | WS.001.2b
PS.base.a5 | PF0_1 | | WS.001.3a
PS.base.a6 | PF0_1 | | WS.001.3b
(6 rows)
QUERY: insert into PField values ('PF1_2', 'Phonelines 1st floor');
QUERY: insert into PSlot values ('PS.1st.ta1', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.ta2', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.ta3', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.ta4', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.ta5', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.ta6', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb1', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb2', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb3', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb4', 'PF1_2', '', '');
QUERY: insert into PSlot values ('PS.1st.tb5', 'PF1_2', '', '');
QUERY: 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;
slotname |pfname|slotlink |backlink
--------------------+------+--------------------+--------------------
PS.1st.a1 |PF1_1 | |WS.101.1a
PS.1st.a2 |PF1_1 | |WS.101.1b
PS.1st.a3 |PF1_1 | |WS.101.2a
PS.1st.a4 |PF1_1 | |WS.101.2b
PS.1st.a5 |PF1_1 | |WS.101.3a
PS.1st.a6 |PF1_1 | |WS.101.3b
PS.1st.b1 |PF1_1 | |WS.102.1a
PS.1st.b2 |PF1_1 | |WS.102.1b
PS.1st.b3 |PF1_1 | |WS.102.2a
PS.1st.b4 |PF1_1 | |WS.102.2b
PS.1st.b5 |PF1_1 | |WS.102.3a
PS.1st.b6 |PF1_1 | |WS.102.3b
PS.1st.c1 |PF1_1 | |WS.105.1a
PS.1st.c2 |PF1_1 | |WS.105.1b
PS.1st.c3 |PF1_1 | |WS.105.2a
PS.1st.c4 |PF1_1 | |WS.105.2b
PS.1st.c5 |PF1_1 | |WS.105.3a
PS.1st.c6 |PF1_1 | |WS.105.3b
PS.1st.d1 |PF1_1 | |WS.106.1a
PS.1st.d2 |PF1_1 | |WS.106.1b
PS.1st.d3 |PF1_1 | |WS.106.2a
PS.1st.d4 |PF1_1 | |WS.106.2b
PS.1st.d5 |PF1_1 | |WS.106.3a
PS.1st.d6 |PF1_1 | |WS.106.3b
PS.1st.ta1 |PF1_2 | |
PS.1st.ta2 |PF1_2 | |
PS.1st.ta3 |PF1_2 | |
PS.1st.ta4 |PF1_2 | |
PS.1st.ta5 |PF1_2 | |
PS.1st.ta6 |PF1_2 | |
PS.1st.tb1 |PF1_2 | |
PS.1st.tb2 |PF1_2 | |
PS.1st.tb3 |PF1_2 | |
PS.1st.tb4 |PF1_2 | |
PS.1st.tb5 |PF1_2 | |
PS.1st.tb6 |PF1_2 | |
PS.base.a1 |PF0_1 | |WS.001.1a
PS.base.a2 |PF0_1 | |WS.001.1b
PS.base.a3 |PF0_1 | |WS.001.2a
PS.base.a4 |PF0_1 | |WS.001.2b
PS.base.a5 |PF0_1 | |WS.001.3a
PS.base.a6 |PF0_1 | |WS.001.3b
PS.base.b1 |PF0_1 | |WS.002.1a
PS.base.b2 |PF0_1 | |WS.002.1b
PS.base.b3 |PF0_1 | |WS.002.2a
PS.base.b4 |PF0_1 | |WS.002.2b
PS.base.b5 |PF0_1 | |WS.002.3a
PS.base.b6 |PF0_1 | |WS.002.3b
PS.base.c1 |PF0_1 | |WS.003.1a
PS.base.c2 |PF0_1 | |WS.003.1b
PS.base.c3 |PF0_1 | |WS.003.2a
PS.base.c4 |PF0_1 | |WS.003.2b
PS.base.c5 |PF0_1 | |WS.003.3a
PS.base.c6 |PF0_1 | |WS.003.3b
PS.base.ta1 |PF0_2 | |
PS.base.ta2 |PF0_2 | |
PS.base.ta3 |PF0_2 | |
PS.base.ta4 |PF0_2 | |
PS.base.ta5 |PF0_2 | |
PS.base.ta6 |PF0_2 | |
PS.base.tb1 |PF0_2 | |
PS.base.tb2 |PF0_2 | |
PS.base.tb3 |PF0_2 | |
PS.base.tb4 |PF0_2 | |
PS.base.tb5 |PF0_2 | |
PS.base.tb6 |PF0_2 | |
insert into PField values ('PF1_2', 'Phonelines 1st floor');
insert into PSlot values ('PS.1st.ta1', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.ta2', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.ta3', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.ta4', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.ta5', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.ta6', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.tb1', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.tb2', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.tb3', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.tb4', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.tb5', 'PF1_2', '', '');
insert into PSlot values ('PS.1st.tb6', 'PF1_2', '', '');
--
-- Fix the wrong name for patchfield PF0_2
--
update PField set name = 'PF0_2' where name = 'PF0_X';
select * from PSlot order by slotname;
slotname | pfname | slotlink | backlink
----------------------+--------+----------------------+----------------------
PS.1st.a1 | PF1_1 | | WS.101.1a
PS.1st.a2 | PF1_1 | | WS.101.1b
PS.1st.a3 | PF1_1 | | WS.101.2a
PS.1st.a4 | PF1_1 | | WS.101.2b
PS.1st.a5 | PF1_1 | | WS.101.3a
PS.1st.a6 | PF1_1 | | WS.101.3b
PS.1st.b1 | PF1_1 | | WS.102.1a
PS.1st.b2 | PF1_1 | | WS.102.1b
PS.1st.b3 | PF1_1 | | WS.102.2a
PS.1st.b4 | PF1_1 | | WS.102.2b
PS.1st.b5 | PF1_1 | | WS.102.3a
PS.1st.b6 | PF1_1 | | WS.102.3b
PS.1st.c1 | PF1_1 | | WS.105.1a
PS.1st.c2 | PF1_1 | | WS.105.1b
PS.1st.c3 | PF1_1 | | WS.105.2a
PS.1st.c4 | PF1_1 | | WS.105.2b
PS.1st.c5 | PF1_1 | | WS.105.3a
PS.1st.c6 | PF1_1 | | WS.105.3b
PS.1st.d1 | PF1_1 | | WS.106.1a
PS.1st.d2 | PF1_1 | | WS.106.1b
PS.1st.d3 | PF1_1 | | WS.106.2a
PS.1st.d4 | PF1_1 | | WS.106.2b
PS.1st.d5 | PF1_1 | | WS.106.3a
PS.1st.d6 | PF1_1 | | WS.106.3b
PS.1st.ta1 | PF1_2 | |
PS.1st.ta2 | PF1_2 | |
PS.1st.ta3 | PF1_2 | |
PS.1st.ta4 | PF1_2 | |
PS.1st.ta5 | PF1_2 | |
PS.1st.ta6 | PF1_2 | |
PS.1st.tb1 | PF1_2 | |
PS.1st.tb2 | PF1_2 | |
PS.1st.tb3 | PF1_2 | |
PS.1st.tb4 | PF1_2 | |
PS.1st.tb5 | PF1_2 | |
PS.1st.tb6 | PF1_2 | |
PS.base.a1 | PF0_1 | | WS.001.1a
PS.base.a2 | PF0_1 | | WS.001.1b
PS.base.a3 | PF0_1 | | WS.001.2a
PS.base.a4 | PF0_1 | | WS.001.2b
PS.base.a5 | PF0_1 | | WS.001.3a
PS.base.a6 | PF0_1 | | WS.001.3b
PS.base.b1 | PF0_1 | | WS.002.1a
PS.base.b2 | PF0_1 | | WS.002.1b
PS.base.b3 | PF0_1 | | WS.002.2a
PS.base.b4 | PF0_1 | | WS.002.2b
PS.base.b5 | PF0_1 | | WS.002.3a
PS.base.b6 | PF0_1 | | WS.002.3b
PS.base.c1 | PF0_1 | | WS.003.1a
PS.base.c2 | PF0_1 | | WS.003.1b
PS.base.c3 | PF0_1 | | WS.003.2a
PS.base.c4 | PF0_1 | | WS.003.2b
PS.base.c5 | PF0_1 | | WS.003.3a
PS.base.c6 | PF0_1 | | WS.003.3b
PS.base.ta1 | PF0_2 | |
PS.base.ta2 | PF0_2 | |
PS.base.ta3 | PF0_2 | |
PS.base.ta4 | PF0_2 | |
PS.base.ta5 | PF0_2 | |
PS.base.ta6 | PF0_2 | |
PS.base.tb1 | PF0_2 | |
PS.base.tb2 | PF0_2 | |
PS.base.tb3 | PF0_2 | |
PS.base.tb4 | PF0_2 | |
PS.base.tb5 | PF0_2 | |
PS.base.tb6 | PF0_2 | |
(66 rows)
QUERY: select * from WSlot order by slotname;
slotname |roomno |slotlink |backlink
--------------------+--------+--------------------+--------------------
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.a5
WS.001.3b |001 | |PS.base.a6
WS.002.1a |002 | |PS.base.b1
WS.002.1b |002 | |PS.base.b2
WS.002.2a |002 | |PS.base.b3
WS.002.2b |002 | |PS.base.b4
WS.002.3a |002 | |PS.base.b5
WS.002.3b |002 | |PS.base.b6
WS.003.1a |003 | |PS.base.c1
WS.003.1b |003 | |PS.base.c2
WS.003.2a |003 | |PS.base.c3
WS.003.2b |003 | |PS.base.c4
WS.003.3a |003 | |PS.base.c5
WS.003.3b |003 | |PS.base.c6
WS.101.1a |101 | |PS.1st.a1
WS.101.1b |101 | |PS.1st.a2
WS.101.2a |101 | |PS.1st.a3
WS.101.2b |101 | |PS.1st.a4
WS.101.3a |101 | |PS.1st.a5
WS.101.3b |101 | |PS.1st.a6
WS.102.1a |102 | |PS.1st.b1
WS.102.1b |102 | |PS.1st.b2
WS.102.2a |102 | |PS.1st.b3
WS.102.2b |102 | |PS.1st.b4
WS.102.3a |102 | |PS.1st.b5
WS.102.3b |102 | |PS.1st.b6
WS.105.1a |105 | |PS.1st.c1
WS.105.1b |105 | |PS.1st.c2
WS.105.2a |105 | |PS.1st.c3
WS.105.2b |105 | |PS.1st.c4
WS.105.3a |105 | |PS.1st.c5
WS.105.3b |105 | |PS.1st.c6
WS.106.1a |106 | |PS.1st.d1
WS.106.1b |106 | |PS.1st.d2
WS.106.2a |106 | |PS.1st.d3
WS.106.2b |106 | |PS.1st.d4
WS.106.3a |106 | |PS.1st.d5
WS.106.3b |106 | |PS.1st.d6
select * from WSlot order by slotname;
slotname | roomno | slotlink | backlink
----------------------+----------+----------------------+----------------------
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.a5
WS.001.3b | 001 | | PS.base.a6
WS.002.1a | 002 | | PS.base.b1
WS.002.1b | 002 | | PS.base.b2
WS.002.2a | 002 | | PS.base.b3
WS.002.2b | 002 | | PS.base.b4
WS.002.3a | 002 | | PS.base.b5
WS.002.3b | 002 | | PS.base.b6
WS.003.1a | 003 | | PS.base.c1
WS.003.1b | 003 | | PS.base.c2
WS.003.2a | 003 | | PS.base.c3
WS.003.2b | 003 | | PS.base.c4
WS.003.3a | 003 | | PS.base.c5
WS.003.3b | 003 | | PS.base.c6
WS.101.1a | 101 | | PS.1st.a1
WS.101.1b | 101 | | PS.1st.a2
WS.101.2a | 101 | | PS.1st.a3
WS.101.2b | 101 | | PS.1st.a4
WS.101.3a | 101 | | PS.1st.a5
WS.101.3b | 101 | | PS.1st.a6
WS.102.1a | 102 | | PS.1st.b1
WS.102.1b | 102 | | PS.1st.b2
WS.102.2a | 102 | | PS.1st.b3
WS.102.2b | 102 | | PS.1st.b4
WS.102.3a | 102 | | PS.1st.b5
WS.102.3b | 102 | | PS.1st.b6
WS.105.1a | 105 | | PS.1st.c1
WS.105.1b | 105 | | PS.1st.c2
WS.105.2a | 105 | | PS.1st.c3
WS.105.2b | 105 | | PS.1st.c4
WS.105.3a | 105 | | PS.1st.c5
WS.105.3b | 105 | | PS.1st.c6
WS.106.1a | 106 | | PS.1st.d1
WS.106.1b | 106 | | PS.1st.d2
WS.106.2a | 106 | | PS.1st.d3
WS.106.2b | 106 | | PS.1st.d4
WS.106.3a | 106 | | PS.1st.d5
WS.106.3b | 106 | | PS.1st.d6
(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');
QUERY: insert into PLine values ('PL.003', '-102', '', 'PS.base.ta3');
QUERY: insert into PLine values ('PL.004', '-103', '', 'PS.base.ta5');
QUERY: insert into PLine values ('PL.005', '-104', '', 'PS.base.ta6');
QUERY: insert into PLine values ('PL.006', '-106', '', 'PS.base.tb2');
QUERY: insert into PLine values ('PL.007', '-108', '', 'PS.base.tb3');
QUERY: insert into PLine values ('PL.008', '-109', '', 'PS.base.tb4');
QUERY: insert into PLine values ('PL.009', '-121', '', 'PS.base.tb5');
QUERY: insert into PLine values ('PL.010', '-122', '', 'PS.base.tb6');
QUERY: insert into PLine values ('PL.015', '-134', '', 'PS.1st.ta1');
QUERY: insert into PLine values ('PL.016', '-137', '', 'PS.1st.ta3');
QUERY: insert into PLine values ('PL.017', '-139', '', 'PS.1st.ta4');
QUERY: insert into PLine values ('PL.018', '-362', '', 'PS.1st.tb1');
QUERY: insert into PLine values ('PL.019', '-363', '', 'PS.1st.tb2');
QUERY: insert into PLine values ('PL.020', '-364', '', 'PS.1st.tb3');
QUERY: insert into PLine values ('PL.021', '-365', '', 'PS.1st.tb5');
QUERY: insert into PLine values ('PL.022', '-367', '', 'PS.1st.tb6');
QUERY: insert into PLine values ('PL.028', '-501', 'Fax entrance', 'PS.base.ta2');
QUERY: insert into PLine values ('PL.029', '-502', 'Fax 1st floor', 'PS.1st.ta1');
QUERY: insert into PHone values ('PH.hc001', 'Hicom standard', 'WS.001.1a');
QUERY: update PSlot set slotlink = 'PS.base.ta1' where slotname = 'PS.base.a1';
QUERY: insert into PHone values ('PH.hc002', 'Hicom standard', 'WS.002.1a');
QUERY: update PSlot set slotlink = 'PS.base.ta5' where slotname = 'PS.base.b1';
QUERY: insert into PHone values ('PH.hc003', 'Hicom standard', 'WS.002.2a');
QUERY: update PSlot set slotlink = 'PS.base.tb2' where slotname = 'PS.base.b3';
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';
QUERY: insert into Hub values ('base.hub1', 'Patchfield PF0_1 hub', 16);
QUERY: insert into System values ('orion', 'PC');
QUERY: insert into IFace values ('IF', 'orion', 'eth0', 'WS.002.1b');
QUERY: update PSlot set slotlink = 'HS.base.hub1.1' where slotname = 'PS.base.b2';
QUERY: select * from PField_v1 where pfname = 'PF0_1' order by slotname;
pfname|slotname |backside |patch
------+--------------------+--------------------------------------------------------+---------------------------------------------
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 -> - |-
--
-- Install the central phone system and create the phone numbers.
-- They are weired on insert to the patchfields. Again the
-- triggers automatically tell the PSlots to update their
-- backlink field.
--
insert into PLine values ('PL.001', '-0', 'Central call', 'PS.base.ta1');
insert into PLine values ('PL.002', '-101', '', 'PS.base.ta2');
insert into PLine values ('PL.003', '-102', '', 'PS.base.ta3');
insert into PLine values ('PL.004', '-103', '', 'PS.base.ta5');
insert into PLine values ('PL.005', '-104', '', 'PS.base.ta6');
insert into PLine values ('PL.006', '-106', '', 'PS.base.tb2');
insert into PLine values ('PL.007', '-108', '', 'PS.base.tb3');
insert into PLine values ('PL.008', '-109', '', 'PS.base.tb4');
insert into PLine values ('PL.009', '-121', '', 'PS.base.tb5');
insert into PLine values ('PL.010', '-122', '', 'PS.base.tb6');
insert into PLine values ('PL.015', '-134', '', 'PS.1st.ta1');
insert into PLine values ('PL.016', '-137', '', 'PS.1st.ta3');
insert into PLine values ('PL.017', '-139', '', 'PS.1st.ta4');
insert into PLine values ('PL.018', '-362', '', 'PS.1st.tb1');
insert into PLine values ('PL.019', '-363', '', 'PS.1st.tb2');
insert into PLine values ('PL.020', '-364', '', 'PS.1st.tb3');
insert into PLine values ('PL.021', '-365', '', 'PS.1st.tb5');
insert into PLine values ('PL.022', '-367', '', 'PS.1st.tb6');
insert into PLine values ('PL.028', '-501', 'Fax entrance', 'PS.base.ta2');
insert into PLine values ('PL.029', '-502', 'Fax 1st floor', 'PS.1st.ta1');
--
-- Buy some phones, plug them into the wall and patch the
-- phone lines to the corresponding patchfield slots.
--
insert into PHone values ('PH.hc001', 'Hicom standard', 'WS.001.1a');
update PSlot set slotlink = 'PS.base.ta1' where slotname = 'PS.base.a1';
insert into PHone values ('PH.hc002', 'Hicom standard', 'WS.002.1a');
update PSlot set slotlink = 'PS.base.ta5' where slotname = 'PS.base.b1';
insert into PHone values ('PH.hc003', 'Hicom standard', 'WS.002.2a');
update PSlot set slotlink = 'PS.base.tb2' where slotname = 'PS.base.b3';
insert into PHone values ('PH.fax001', 'Canon fax', 'WS.001.2a');
update PSlot set slotlink = 'PS.base.ta2' where slotname = 'PS.base.a3';
--
-- Install a hub at one of the patchfields, plug a computers
-- ethernet interface into the wall and patch it to the hub.
--
insert into Hub values ('base.hub1', 'Patchfield PF0_1 hub', 16);
insert into System values ('orion', 'PC');
insert into IFace values ('IF', 'orion', 'eth0', 'WS.002.1b');
update PSlot set slotlink = 'HS.base.hub1.1' where slotname = 'PS.base.b2';
--
-- Now we take a look at the patchfield
--
select * from PField_v1 where pfname = 'PF0_1' order by slotname;
pfname | slotname | backside | patch
--------+----------------------+----------------------------------------------------------+-----------------------------------------------
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)
QUERY: select * from PField_v1 where pfname = 'PF0_2' order by slotname;
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.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.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.ta6 |Phone line -104 |-
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.tb3 |Phone line -108 |-
PF0_2 |PS.base.tb4 |Phone line -109 |-
PF0_2 |PS.base.tb5 |Phone line -121 |-
PF0_2 |PS.base.tb6 |Phone line -122 |-
select * from PField_v1 where pfname = 'PF0_2' order by slotname;
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.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.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.ta6 | Phone line -104 | -
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.tb3 | Phone line -108 | -
PF0_2 | PS.base.tb4 | Phone line -109 | -
PF0_2 | PS.base.tb5 | Phone line -121 | -
PF0_2 | PS.base.tb6 | Phone line -122 | -
(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
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
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
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
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
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
QUERY: insert into HSlot values ('HS', 'base.hub1', 20, '');
insert into HSlot values ('HS', 'base.hub1', 20, '');
ERROR: no manual manipulation of HSlot
QUERY: delete from HSlot;
delete from 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
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)
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;
QUERY: DECLARE foo14 CURSOR FOR
DECLARE foo14 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 51;
QUERY: DECLARE foo15 CURSOR FOR
DECLARE foo15 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 52;
QUERY: DECLARE foo16 CURSOR FOR
DECLARE foo16 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 53;
QUERY: DECLARE foo17 CURSOR FOR
DECLARE foo17 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 54;
QUERY: DECLARE foo18 CURSOR FOR
DECLARE foo18 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 55;
QUERY: DECLARE foo19 CURSOR FOR
DECLARE foo19 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 56;
QUERY: DECLARE foo20 CURSOR FOR
DECLARE foo20 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 57;
QUERY: DECLARE foo21 CURSOR FOR
DECLARE foo21 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 58;
QUERY: DECLARE foo22 CURSOR FOR
DECLARE foo22 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 59;
QUERY: DECLARE foo23 CURSOR FOR
DECLARE foo23 CURSOR FOR
SELECT * FROM onek WHERE unique1 = 60;
QUERY: DECLARE foo24 CURSOR FOR
DECLARE foo24 CURSOR FOR
SELECT * FROM onek2 WHERE unique1 = 50;
QUERY: DECLARE foo25 CURSOR FOR
DECLARE foo25 CURSOR FOR
SELECT * FROM onek2 WHERE unique1 = 60;
QUERY: FETCH all in foo13;
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
FETCH all in foo13;
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
(1 row)
QUERY: FETCH all in foo14;
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
FETCH all in foo14;
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
(1 row)
QUERY: FETCH all in foo15;
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
FETCH all in foo15;
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
(1 row)
QUERY: FETCH all in foo16;
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
FETCH all in foo16;
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
(1 row)
QUERY: FETCH all in foo17;
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
FETCH all in foo17;
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
(1 row)
QUERY: FETCH all in foo18;
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
FETCH all in foo18;
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
(1 row)
QUERY: FETCH all in foo19;
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
FETCH all in foo19;
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
(1 row)
QUERY: FETCH all in foo20;
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
FETCH all in foo20;
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
(1 row)
QUERY: FETCH all in foo21;
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
FETCH all in foo21;
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
(1 row)
QUERY: FETCH all in foo22;
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
FETCH all in foo22;
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
(1 row)
QUERY: FETCH all in foo23;
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
FETCH all in foo23;
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
(1 row)
QUERY: FETCH all in foo24;
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
FETCH all in foo24;
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
(1 row)
QUERY: FETCH all in foo25;
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
FETCH all in foo25;
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
(1 row)
QUERY: CLOSE foo13;
QUERY: CLOSE foo14;
QUERY: CLOSE foo15;
QUERY: CLOSE foo16;
QUERY: CLOSE foo17;
QUERY: CLOSE foo18;
QUERY: CLOSE foo19;
QUERY: CLOSE foo20;
QUERY: CLOSE foo21;
QUERY: CLOSE foo22;
QUERY: CLOSE foo23;
QUERY: CLOSE foo24;
QUERY: CLOSE foo25;
QUERY: END;
CLOSE foo13;
CLOSE foo14;
CLOSE foo15;
CLOSE foo16;
CLOSE foo17;
CLOSE foo18;
CLOSE foo19;
CLOSE foo20;
CLOSE foo21;
CLOSE foo22;
CLOSE foo23;
CLOSE foo24;
CLOSE foo25;
END;
QUERY: create table rtest_t1 (a int4, b int4);
QUERY: create table rtest_t2 (a int4, b int4);
QUERY: create table rtest_t3 (a int4, b int4);
QUERY: create view rtest_v1 as select * from rtest_t1;
QUERY: create rule rtest_v1_ins as on insert to rtest_v1 do instead
--
-- RULES
-- From Jan's original setup_ruletest.sql and run_ruletest.sql
-- - thomas 1998-09-13
--
--
-- Tables and rules for the view test
--
create table rtest_t1 (a int4, b int4);
create table rtest_t2 (a int4, b int4);
create table rtest_t3 (a int4, b int4);
create view rtest_v1 as select * from rtest_t1;
create rule rtest_v1_ins as on insert to rtest_v1 do instead
insert into rtest_t1 values (new.a, new.b);
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
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;
QUERY: create table rtest_system (sysname text, sysdesc text);
QUERY: create table rtest_interface (sysname text, ifname text);
QUERY: create table rtest_person (pname text, pdesc text);
QUERY: create table rtest_admin (pname text, sysname text);
QUERY: create rule rtest_sys_upd as on update to rtest_system do (
update rtest_interface set sysname = new.sysname
--
-- Tables and rules for the constraint update/delete test
--
-- Note:
-- Now that we have multiple action rule support, we check
-- 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;
update rtest_admin set sysname = new.sysname
update rtest_admin set sysname = new.sysname
where sysname = old.sysname
);
QUERY: create rule rtest_sys_del as on delete to rtest_system do (
create rule rtest_sys_del as on delete to rtest_system do (
delete from rtest_interface where sysname = old.sysname;
delete from rtest_admin where sysname = old.sysname;
);
QUERY: create rule rtest_pers_upd as on update to rtest_person do
create rule rtest_pers_upd as on update to rtest_person do
update rtest_admin set pname = new.pname where pname = old.pname;
QUERY: create rule rtest_pers_del as on delete to rtest_person do
create rule rtest_pers_del as on delete to rtest_person do
delete from rtest_admin where pname = old.pname;
QUERY: create table rtest_emp (ename char(20), salary money);
QUERY: create table rtest_emplog (ename char(20), who name, action char(10), newsal money, oldsal money);
QUERY: create table rtest_empmass (ename char(20), salary money);
QUERY: create rule rtest_emp_ins as on insert to rtest_emp do
--
-- Tables and rules for the logging test
--
create table rtest_emp (ename char(20), salary money);
create table rtest_emplog (ename char(20), who name, action char(10), newsal money, oldsal money);
create table rtest_empmass (ename char(20), salary money);
create rule rtest_emp_ins as on insert to rtest_emp do
insert into rtest_emplog values (new.ename, current_user,
'hired', new.salary, '0.00');
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,
'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,
'fired', '0.00', old.salary);
QUERY: create table rtest_t4 (a int4, b text);
QUERY: create table rtest_t5 (a int4, b text);
QUERY: create table rtest_t6 (a int4, b text);
QUERY: create table rtest_t7 (a int4, b text);
QUERY: create table rtest_t8 (a int4, b text);
QUERY: create table rtest_t9 (a int4, b text);
QUERY: create rule rtest_t4_ins1 as on insert to rtest_t4
--
-- Tables and rules for the multiple cascaded qualified instead
-- rule test
--
create table rtest_t4 (a int4, b text);
create table rtest_t5 (a int4, b text);
create table rtest_t6 (a int4, b text);
create table rtest_t7 (a int4, b text);
create table rtest_t8 (a int4, b text);
create table rtest_t9 (a int4, b text);
create rule rtest_t4_ins1 as on insert to rtest_t4
where new.a >= 10 and new.a < 20 do instead
insert into rtest_t5 values (new.a, new.b);
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
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
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
insert into rtest_t8 values (new.a, new.b);
QUERY: create table rtest_order1 (a int4);
QUERY: create table rtest_order2 (a int4, b int4, c text);
QUERY: create sequence rtest_seq;
QUERY: create rule rtest_order_r3 as on insert to rtest_order1 do instead
--
-- Tables and rules for the rule fire order test
--
create table rtest_order1 (a int4);
create table rtest_order2 (a int4, b int4, c text);
create sequence rtest_seq;
create rule rtest_order_r3 as on insert to rtest_order1 do instead
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
'rule 3 - this should run 3rd or 4th');
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
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
'rule 4 - this should run 2nd');
QUERY: create rule rtest_order_r2 as on insert to rtest_order1 do
create rule rtest_order_r2 as on insert to rtest_order1 do
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
'rule 2 - this should run 1st');
QUERY: create rule rtest_order_r1 as on insert to rtest_order1 do instead
create rule rtest_order_r1 as on insert to rtest_order1 do instead
insert into rtest_order2 values (new.a, nextval('rtest_seq'),
'rule 1 - this should run 3rd or 4th');
QUERY: create table rtest_nothn1 (a int4, b text);
QUERY: create table rtest_nothn2 (a int4, b text);
QUERY: create table rtest_nothn3 (a int4, b text);
QUERY: create table rtest_nothn4 (a int4, b text);
QUERY: create rule rtest_nothn_r1 as on insert to rtest_nothn1
--
-- Tables and rules for the instead nothing test
--
create table rtest_nothn1 (a int4, b text);
create table rtest_nothn2 (a int4, b text);
create table rtest_nothn3 (a int4, b text);
create table rtest_nothn4 (a int4, b text);
create rule rtest_nothn_r1 as on insert to rtest_nothn1
where new.a >= 10 and new.a < 20 do instead (select 1);
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;
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
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;
QUERY: insert into rtest_t2 values (1, 21);
QUERY: insert into rtest_t2 values (2, 22);
QUERY: insert into rtest_t2 values (3, 23);
QUERY: insert into rtest_t3 values (1, 31);
QUERY: insert into rtest_t3 values (2, 32);
QUERY: insert into rtest_t3 values (3, 33);
QUERY: insert into rtest_t3 values (4, 34);
QUERY: insert into rtest_t3 values (5, 35);
QUERY: insert into rtest_v1 values (1, 11);
QUERY: insert into rtest_v1 values (2, 12);
QUERY: select * from rtest_v1;
a| b
-+--
1|11
2|12
--
-- Tests on a view that is select * of a table
-- and has insert/update/delete instead rules to
-- behave close like the real table.
--
--
-- We need test date later
--
insert into rtest_t2 values (1, 21);
insert into rtest_t2 values (2, 22);
insert into rtest_t2 values (3, 23);
insert into rtest_t3 values (1, 31);
insert into rtest_t3 values (2, 32);
insert into rtest_t3 values (3, 33);
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)
QUERY: delete from rtest_v1 where a = 1;
QUERY: select * from rtest_v1;
a| b
-+--
2|12
-- delete with constant expression
delete from rtest_v1 where a = 1;
select * from rtest_v1;
a | b
---+----
2 | 12
(1 row)
QUERY: insert into rtest_v1 values (1, 11);
QUERY: delete from rtest_v1 where b = 12;
QUERY: select * from rtest_v1;
a| b
-+--
1|11
insert into rtest_v1 values (1, 11);
delete from rtest_v1 where b = 12;
select * from rtest_v1;
a | b
---+----
1 | 11
(1 row)
QUERY: insert into rtest_v1 values (2, 12);
QUERY: insert into rtest_v1 values (2, 13);
QUERY: select * from rtest_v1;
a| b
-+--
1|11
2|12
2|13
insert into rtest_v1 values (2, 12);
insert into rtest_v1 values (2, 13);
select * from rtest_v1;
a | b
---+----
1 | 11
2 | 12
2 | 13
(3 rows)
** Remember the delete rule on rtest_v1: It says
** DO INSTEAD DELETE FROM rtest_t1 WHERE a = old.a
** So this time both rows with a = 2 must get deleted
QUERY: delete from rtest_v1 where b = 12;
QUERY: select * from rtest_v1;
a| b
-+--
1|11
\p
** Remember the delete rule on rtest_v1: It says
** DO INSTEAD DELETE FROM rtest_t1 WHERE a = old.a
** So this time both rows with a = 2 must get deleted
\r
delete from rtest_v1 where b = 12;
select * from rtest_v1;
a | b
---+----
1 | 11
(1 row)
QUERY: delete from rtest_v1;
QUERY: insert into rtest_v1 select * from rtest_t2;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
2|22
3|23
delete from rtest_v1;
-- insert select
insert into rtest_v1 select * from rtest_t2;
select * from rtest_v1;
a | b
---+----
1 | 21
2 | 22
3 | 23
(3 rows)
QUERY: delete from rtest_v1;
QUERY: insert into rtest_v1 (b, a) select b, a from rtest_t2;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
2|22
3|23
delete from rtest_v1;
-- same with swapped targetlist
insert into rtest_v1 (b, a) select b, a from rtest_t2;
select * from rtest_v1;
a | b
---+----
1 | 21
2 | 22
3 | 23
(3 rows)
QUERY: insert into rtest_v1 (a) select a from rtest_t3;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
2|22
3|23
1|
2|
3|
4|
5|
-- now with only one target attribute
insert into rtest_v1 (a) select a from rtest_t3;
select * from rtest_v1;
a | b
---+----
1 | 21
2 | 22
3 | 23
1 |
2 |
3 |
4 |
5 |
(8 rows)
QUERY: select * from rtest_v1 where b isnull;
a|b
-+-
1|
2|
3|
4|
5|
select * from rtest_v1 where b isnull;
a | b
---+---
1 |
2 |
3 |
4 |
5 |
(5 rows)
QUERY: update rtest_t1 set a = a + 10 where b isnull;
QUERY: delete from rtest_v1 where b isnull;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
2|22
3|23
-- let attribute a differ (must be done on rtest_t1 - see above)
update rtest_t1 set a = a + 10 where b isnull;
delete from rtest_v1 where b isnull;
select * from rtest_v1;
a | b
---+----
1 | 21
2 | 22
3 | 23
(3 rows)
QUERY: update rtest_v1 set b = 42 where a = 2;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
3|23
2|42
-- now updates with constant expression
update rtest_v1 set b = 42 where a = 2;
select * from rtest_v1;
a | b
---+----
1 | 21
3 | 23
2 | 42
(3 rows)
QUERY: update rtest_v1 set b = 99 where b = 42;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
3|23
2|99
update rtest_v1 set b = 99 where b = 42;
select * from rtest_v1;
a | b
---+----
1 | 21
3 | 23
2 | 99
(3 rows)
QUERY: update rtest_v1 set b = 88 where b < 50;
QUERY: select * from rtest_v1;
a| b
-+--
2|99
1|88
3|88
update rtest_v1 set b = 88 where b < 50;
select * from rtest_v1;
a | b
---+----
2 | 99
1 | 88
3 | 88
(3 rows)
QUERY: delete from rtest_v1;
QUERY: insert into rtest_v1 select rtest_t2.a, rtest_t3.b where rtest_t2.a = rtest_t3.a;
QUERY: select * from rtest_v1;
a| b
-+--
1|31
2|32
3|33
delete from rtest_v1;
insert into rtest_v1 select rtest_t2.a, rtest_t3.b where rtest_t2.a = rtest_t3.a;
select * from rtest_v1;
a | b
---+----
1 | 31
2 | 32
3 | 33
(3 rows)
QUERY: update rtest_v1 set b = rtest_t2.b where a = rtest_t2.a;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
2|22
3|23
-- updates in a mergejoin
update rtest_v1 set b = rtest_t2.b where a = rtest_t2.a;
select * from rtest_v1;
a | b
---+----
1 | 21
2 | 22
3 | 23
(3 rows)
QUERY: insert into rtest_v1 select * from rtest_t3;
QUERY: select * from rtest_v1;
a| b
-+--
1|21
2|22
3|23
1|31
2|32
3|33
4|34
5|35
insert into rtest_v1 select * from rtest_t3;
select * from rtest_v1;
a | b
---+----
1 | 21
2 | 22
3 | 23
1 | 31
2 | 32
3 | 33
4 | 34
5 | 35
(8 rows)
QUERY: update rtest_t1 set a = a + 10 where b > 30;
QUERY: select * from rtest_v1;
a| b
--+--
1|21
2|22
3|23
11|31
12|32
13|33
14|34
15|35
update rtest_t1 set a = a + 10 where b > 30;
select * from rtest_v1;
a | b
----+----
1 | 21
2 | 22
3 | 23
11 | 31
12 | 32
13 | 33
14 | 34
15 | 35
(8 rows)
QUERY: update rtest_v1 set a = rtest_t3.a + 20 where b = rtest_t3.b;
QUERY: select * from rtest_v1;
a| b
--+--
1|21
2|22
3|23
21|31
22|32
23|33
24|34
25|35
update rtest_v1 set a = rtest_t3.a + 20 where b = rtest_t3.b;
select * from rtest_v1;
a | b
----+----
1 | 21
2 | 22
3 | 23
21 | 31
22 | 32
23 | 33
24 | 34
25 | 35
(8 rows)
QUERY: insert into rtest_system values ('orion', 'Linux Jan Wieck');
QUERY: insert into rtest_system values ('notjw', 'WinNT Jan Wieck (notebook)');
QUERY: insert into rtest_system values ('neptun', 'Fileserver');
QUERY: insert into rtest_interface values ('orion', 'eth0');
QUERY: insert into rtest_interface values ('orion', 'eth1');
QUERY: insert into rtest_interface values ('notjw', 'eth0');
QUERY: insert into rtest_interface values ('neptun', 'eth0');
QUERY: insert into rtest_person values ('jw', 'Jan Wieck');
QUERY: insert into rtest_person values ('bm', 'Bruce Momjian');
QUERY: insert into rtest_admin values ('jw', 'orion');
QUERY: insert into rtest_admin values ('jw', 'notjw');
QUERY: insert into rtest_admin values ('bm', 'neptun');
QUERY: update rtest_system set sysname = 'pluto' where sysname = 'neptun';
QUERY: select * from rtest_interface;
sysname|ifname
-------+------
orion |eth0
orion |eth1
notjw |eth0
pluto |eth0
--
-- Test for constraint updates/deletes
--
insert into rtest_system values ('orion', 'Linux Jan Wieck');
insert into rtest_system values ('notjw', 'WinNT Jan Wieck (notebook)');
insert into rtest_system values ('neptun', 'Fileserver');
insert into rtest_interface values ('orion', 'eth0');
insert into rtest_interface values ('orion', 'eth1');
insert into rtest_interface values ('notjw', 'eth0');
insert into rtest_interface values ('neptun', 'eth0');
insert into rtest_person values ('jw', 'Jan Wieck');
insert into rtest_person values ('bm', 'Bruce Momjian');
insert into rtest_admin values ('jw', 'orion');
insert into rtest_admin values ('jw', 'notjw');
insert into rtest_admin values ('bm', 'neptun');
update rtest_system set sysname = 'pluto' where sysname = 'neptun';
select * from rtest_interface;
sysname | ifname
---------+--------
orion | eth0
orion | eth1
notjw | eth0
pluto | eth0
(4 rows)
QUERY: select * from rtest_admin;
pname|sysname
-----+-------
jw |orion
jw |notjw
bm |pluto
select * from rtest_admin;
pname | sysname
-------+---------
jw | orion
jw | notjw
bm | pluto
(3 rows)
QUERY: update rtest_person set pname = 'jwieck' where pdesc = 'Jan Wieck';
QUERY: select * from rtest_admin order by pname, sysname;
pname |sysname
------+-------
bm |pluto
jwieck|notjw
jwieck|orion
update rtest_person set pname = 'jwieck' where pdesc = 'Jan Wieck';
-- Note: use ORDER BY here to ensure consistent output across all systems.
-- 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().
select * from rtest_admin order by pname, sysname;
pname | sysname
--------+---------
bm | pluto
jwieck | notjw
jwieck | orion
(3 rows)
QUERY: delete from rtest_system where sysname = 'orion';
QUERY: select * from rtest_interface;
sysname|ifname
-------+------
notjw |eth0
pluto |eth0
delete from rtest_system where sysname = 'orion';
select * from rtest_interface;
sysname | ifname
---------+--------
notjw | eth0
pluto | eth0
(2 rows)
QUERY: select * from rtest_admin;
pname |sysname
------+-------
bm |pluto
jwieck|notjw
select * from rtest_admin;
pname | sysname
--------+---------
bm | pluto
jwieck | notjw
(2 rows)
QUERY: insert into rtest_emp values ('wiech', '5000.00');
QUERY: insert into rtest_emp values ('gates', '80000.00');
QUERY: update rtest_emp set ename = 'wiecx' where ename = 'wiech';
QUERY: update rtest_emp set ename = 'wieck', salary = '6000.00' where ename = 'wiecx';
QUERY: update rtest_emp set salary = '7000.00' where ename = 'wieck';
QUERY: delete from rtest_emp where ename = 'gates';
QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal;
ename |matches user|action |newsal |oldsal
--------------------+------------+----------+----------+----------
gates |t |fired |$0.00 |$80,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
--
-- Rule qualification test
--
insert into rtest_emp values ('wiech', '5000.00');
insert into rtest_emp values ('gates', '80000.00');
update rtest_emp set ename = 'wiecx' where ename = 'wiech';
update rtest_emp set ename = 'wieck', salary = '6000.00' where ename = 'wiecx';
update rtest_emp set salary = '7000.00' where ename = 'wieck';
delete from rtest_emp where ename = 'gates';
select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal;
ename | matches user | action | newsal | oldsal
----------------------+--------------+------------+------------+------------
gates | t | fired | $0.00 | $80,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)
QUERY: insert into rtest_empmass values ('meyer', '4000.00');
QUERY: insert into rtest_empmass values ('maier', '5000.00');
QUERY: insert into rtest_empmass values ('mayr', '6000.00');
QUERY: insert into rtest_emp select * from rtest_empmass;
QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal;
ename |matches user|action |newsal |oldsal
--------------------+------------+----------+----------+----------
gates |t |fired |$0.00 |$80,000.00
gates |t |hired |$80,000.00|$0.00
maier |t |hired |$5,000.00 |$0.00
mayr |t |hired |$6,000.00 |$0.00
meyer |t |hired |$4,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
insert into rtest_empmass values ('meyer', '4000.00');
insert into rtest_empmass values ('maier', '5000.00');
insert into rtest_empmass values ('mayr', '6000.00');
insert into rtest_emp select * from rtest_empmass;
select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal;
ename | matches user | action | newsal | oldsal
----------------------+--------------+------------+------------+------------
gates | t | fired | $0.00 | $80,000.00
gates | t | hired | $80,000.00 | $0.00
maier | t | hired | $5,000.00 | $0.00
mayr | t | hired | $6,000.00 | $0.00
meyer | t | hired | $4,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
(8 rows)
QUERY: update rtest_empmass set salary = salary + '1000.00';
QUERY: update rtest_emp set salary = rtest_empmass.salary where ename = rtest_empmass.ename;
QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal;
ename |matches user|action |newsal |oldsal
--------------------+------------+----------+----------+----------
gates |t |fired |$0.00 |$80,000.00
gates |t |hired |$80,000.00|$0.00
maier |t |hired |$5,000.00 |$0.00
maier |t |honored |$6,000.00 |$5,000.00
mayr |t |hired |$6,000.00 |$0.00
mayr |t |honored |$7,000.00 |$6,000.00
meyer |t |hired |$4,000.00 |$0.00
meyer |t |honored |$5,000.00 |$4,000.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
update rtest_empmass set salary = salary + '1000.00';
update rtest_emp set salary = rtest_empmass.salary where ename = rtest_empmass.ename;
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
----------------------+--------------+------------+------------+------------
gates | t | fired | $0.00 | $80,000.00
gates | t | hired | $80,000.00 | $0.00
maier | t | hired | $5,000.00 | $0.00
maier | t | honored | $6,000.00 | $5,000.00
mayr | t | hired | $6,000.00 | $0.00
mayr | t | honored | $7,000.00 | $6,000.00
meyer | t | hired | $4,000.00 | $0.00
meyer | t | honored | $5,000.00 | $4,000.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
(11 rows)
QUERY: delete from rtest_emp where ename = rtest_empmass.ename;
QUERY: select ename, who = current_user as "matches user", action, newsal, oldsal from rtest_emplog order by ename, action, newsal;
ename |matches user|action |newsal |oldsal
--------------------+------------+----------+----------+----------
gates |t |fired |$0.00 |$80,000.00
gates |t |hired |$80,000.00|$0.00
maier |t |fired |$0.00 |$6,000.00
maier |t |hired |$5,000.00 |$0.00
maier |t |honored |$6,000.00 |$5,000.00
mayr |t |fired |$0.00 |$7,000.00
mayr |t |hired |$6,000.00 |$0.00
mayr |t |honored |$7,000.00 |$6,000.00
meyer |t |fired |$0.00 |$5,000.00
meyer |t |hired |$4,000.00 |$0.00
meyer |t |honored |$5,000.00 |$4,000.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
delete from rtest_emp where ename = rtest_empmass.ename;
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
----------------------+--------------+------------+------------+------------
gates | t | fired | $0.00 | $80,000.00
gates | t | hired | $80,000.00 | $0.00
maier | t | fired | $0.00 | $6,000.00
maier | t | hired | $5,000.00 | $0.00
maier | t | honored | $6,000.00 | $5,000.00
mayr | t | fired | $0.00 | $7,000.00
mayr | t | hired | $6,000.00 | $0.00
mayr | t | honored | $7,000.00 | $6,000.00
meyer | t | fired | $0.00 | $5,000.00
meyer | t | hired | $4,000.00 | $0.00
meyer | t | honored | $5,000.00 | $4,000.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
(14 rows)
QUERY: insert into rtest_t4 values (1, 'Record should go to rtest_t4');
QUERY: insert into rtest_t4 values (2, 'Record should go to rtest_t4');
QUERY: insert into rtest_t4 values (10, 'Record should go to rtest_t5');
QUERY: insert into rtest_t4 values (15, 'Record should go to rtest_t5');
QUERY: insert into rtest_t4 values (19, 'Record should go to rtest_t5 and t7');
QUERY: insert into rtest_t4 values (20, 'Record should go to rtest_t4 and t6');
QUERY: insert into rtest_t4 values (26, 'Record should go to rtest_t4 and t8');
QUERY: insert into rtest_t4 values (28, 'Record should go to rtest_t4 and t8');
QUERY: insert into rtest_t4 values (30, 'Record should go to rtest_t4');
QUERY: insert into rtest_t4 values (40, 'Record should go to rtest_t4');
QUERY: select * from rtest_t4;
a|b
--+-----------------------------------
1|Record should go to rtest_t4
2|Record should go to rtest_t4
20|Record should go to rtest_t4 and t6
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
30|Record should go to rtest_t4
40|Record should go to rtest_t4
--
-- Multiple cascaded qualified instead rule test
--
insert into rtest_t4 values (1, 'Record should go to rtest_t4');
insert into rtest_t4 values (2, 'Record should go to rtest_t4');
insert into rtest_t4 values (10, 'Record should go to rtest_t5');
insert into rtest_t4 values (15, 'Record should go to rtest_t5');
insert into rtest_t4 values (19, 'Record should go to rtest_t5 and t7');
insert into rtest_t4 values (20, 'Record should go to rtest_t4 and t6');
insert into rtest_t4 values (26, 'Record should go to rtest_t4 and t8');
insert into rtest_t4 values (28, 'Record should go to rtest_t4 and t8');
insert into rtest_t4 values (30, 'Record should go to rtest_t4');
insert into rtest_t4 values (40, 'Record should go to rtest_t4');
select * from rtest_t4;
a | b
----+-------------------------------------
1 | Record should go to rtest_t4
2 | Record should go to rtest_t4
20 | Record should go to rtest_t4 and t6
26 | Record should go to rtest_t4 and t8
28 | Record should go to rtest_t4 and t8
30 | Record should go to rtest_t4
40 | Record should go to rtest_t4
(7 rows)
QUERY: select * from rtest_t5;
a|b
--+-----------------------------------
10|Record should go to rtest_t5
15|Record should go to rtest_t5
19|Record should go to rtest_t5 and t7
select * from rtest_t5;
a | b
----+-------------------------------------
10 | Record should go to rtest_t5
15 | Record should go to rtest_t5
19 | Record should go to rtest_t5 and t7
(3 rows)
QUERY: select * from rtest_t6;
a|b
--+-----------------------------------
20|Record should go to rtest_t4 and t6
select * from rtest_t6;
a | b
----+-------------------------------------
20 | Record should go to rtest_t4 and t6
(1 row)
QUERY: select * from rtest_t7;
a|b
--+-----------------------------------
19|Record should go to rtest_t5 and t7
select * from rtest_t7;
a | b
----+-------------------------------------
19 | Record should go to rtest_t5 and t7
(1 row)
QUERY: select * from rtest_t8;
a|b
--+-----------------------------------
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
select * from rtest_t8;
a | b
----+-------------------------------------
26 | Record should go to rtest_t4 and t8
28 | Record should go to rtest_t4 and t8
(2 rows)
QUERY: delete from rtest_t4;
QUERY: delete from rtest_t5;
QUERY: delete from rtest_t6;
QUERY: delete from rtest_t7;
QUERY: delete from rtest_t8;
QUERY: insert into rtest_t9 values (1, 'Record should go to rtest_t4');
QUERY: insert into rtest_t9 values (2, 'Record should go to rtest_t4');
QUERY: insert into rtest_t9 values (10, 'Record should go to rtest_t5');
QUERY: insert into rtest_t9 values (15, 'Record should go to rtest_t5');
QUERY: insert into rtest_t9 values (19, 'Record should go to rtest_t5 and t7');
QUERY: insert into rtest_t9 values (20, 'Record should go to rtest_t4 and t6');
QUERY: insert into rtest_t9 values (26, 'Record should go to rtest_t4 and t8');
QUERY: insert into rtest_t9 values (28, 'Record should go to rtest_t4 and t8');
QUERY: insert into rtest_t9 values (30, 'Record should go to rtest_t4');
QUERY: insert into rtest_t9 values (40, 'Record should go to rtest_t4');
QUERY: insert into rtest_t4 select * from rtest_t9 where a < 20;
QUERY: select * from rtest_t4;
a|b
-+----------------------------
1|Record should go to rtest_t4
2|Record should go to rtest_t4
delete from rtest_t4;
delete from rtest_t5;
delete from rtest_t6;
delete from rtest_t7;
delete from rtest_t8;
insert into rtest_t9 values (1, 'Record should go to rtest_t4');
insert into rtest_t9 values (2, 'Record should go to rtest_t4');
insert into rtest_t9 values (10, 'Record should go to rtest_t5');
insert into rtest_t9 values (15, 'Record should go to rtest_t5');
insert into rtest_t9 values (19, 'Record should go to rtest_t5 and t7');
insert into rtest_t9 values (20, 'Record should go to rtest_t4 and t6');
insert into rtest_t9 values (26, 'Record should go to rtest_t4 and t8');
insert into rtest_t9 values (28, 'Record should go to rtest_t4 and t8');
insert into rtest_t9 values (30, 'Record should go to rtest_t4');
insert into rtest_t9 values (40, 'Record should go to rtest_t4');
insert into rtest_t4 select * from rtest_t9 where a < 20;
select * from rtest_t4;
a | b
---+------------------------------
1 | Record should go to rtest_t4
2 | Record should go to rtest_t4
(2 rows)
QUERY: select * from rtest_t5;
a|b
--+-----------------------------------
10|Record should go to rtest_t5
15|Record should go to rtest_t5
19|Record should go to rtest_t5 and t7
select * from rtest_t5;
a | b
----+-------------------------------------
10 | Record should go to rtest_t5
15 | Record should go to rtest_t5
19 | Record should go to rtest_t5 and t7
(3 rows)
QUERY: select * from rtest_t6;
a|b
-+-
select * from rtest_t6;
a | b
---+---
(0 rows)
QUERY: select * from rtest_t7;
a|b
--+-----------------------------------
19|Record should go to rtest_t5 and t7
select * from rtest_t7;
a | b
----+-------------------------------------
19 | Record should go to rtest_t5 and t7
(1 row)
QUERY: select * from rtest_t8;
a|b
-+-
select * from rtest_t8;
a | b
---+---
(0 rows)
QUERY: insert into rtest_t4 select * from rtest_t9 where b ~ 'and t8';
QUERY: select * from rtest_t4;
a|b
--+-----------------------------------
1|Record should go to rtest_t4
2|Record should go to rtest_t4
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
insert into rtest_t4 select * from rtest_t9 where b ~ 'and t8';
select * from rtest_t4;
a | b
----+-------------------------------------
1 | Record should go to rtest_t4
2 | Record should go to rtest_t4
26 | Record should go to rtest_t4 and t8
28 | Record should go to rtest_t4 and t8
(4 rows)
QUERY: select * from rtest_t5;
a|b
--+-----------------------------------
10|Record should go to rtest_t5
15|Record should go to rtest_t5
19|Record should go to rtest_t5 and t7
select * from rtest_t5;
a | b
----+-------------------------------------
10 | Record should go to rtest_t5
15 | Record should go to rtest_t5
19 | Record should go to rtest_t5 and t7
(3 rows)
QUERY: select * from rtest_t6;
a|b
-+-
select * from rtest_t6;
a | b
---+---
(0 rows)
QUERY: select * from rtest_t7;
a|b
--+-----------------------------------
19|Record should go to rtest_t5 and t7
select * from rtest_t7;
a | b
----+-------------------------------------
19 | Record should go to rtest_t5 and t7
(1 row)
QUERY: select * from rtest_t8;
a|b
--+-----------------------------------
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
select * from rtest_t8;
a | b
----+-------------------------------------
26 | Record should go to rtest_t4 and t8
28 | Record should go to rtest_t4 and t8
(2 rows)
QUERY: insert into rtest_t4 select a + 1, b from rtest_t9 where a in (20, 30, 40);
QUERY: select * from rtest_t4;
a|b
--+-----------------------------------
1|Record should go to rtest_t4
2|Record should go to rtest_t4
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
21|Record should go to rtest_t4 and t6
31|Record should go to rtest_t4
41|Record should go to rtest_t4
insert into rtest_t4 select a + 1, b from rtest_t9 where a in (20, 30, 40);
select * from rtest_t4;
a | b
----+-------------------------------------
1 | Record should go to rtest_t4
2 | Record should go to rtest_t4
26 | Record should go to rtest_t4 and t8
28 | Record should go to rtest_t4 and t8
21 | Record should go to rtest_t4 and t6
31 | Record should go to rtest_t4
41 | Record should go to rtest_t4
(7 rows)
QUERY: select * from rtest_t5;
a|b
--+-----------------------------------
10|Record should go to rtest_t5
15|Record should go to rtest_t5
19|Record should go to rtest_t5 and t7
select * from rtest_t5;
a | b
----+-------------------------------------
10 | Record should go to rtest_t5
15 | Record should go to rtest_t5
19 | Record should go to rtest_t5 and t7
(3 rows)
QUERY: select * from rtest_t6;
a|b
--+-----------------------------------
21|Record should go to rtest_t4 and t6
select * from rtest_t6;
a | b
----+-------------------------------------
21 | Record should go to rtest_t4 and t6
(1 row)
QUERY: select * from rtest_t7;
a|b
--+-----------------------------------
19|Record should go to rtest_t5 and t7
select * from rtest_t7;
a | b
----+-------------------------------------
19 | Record should go to rtest_t5 and t7
(1 row)
QUERY: select * from rtest_t8;
a|b
--+-----------------------------------
26|Record should go to rtest_t4 and t8
28|Record should go to rtest_t4 and t8
select * from rtest_t8;
a | b
----+-------------------------------------
26 | Record should go to rtest_t4 and t8
28 | Record should go to rtest_t4 and t8
(2 rows)
QUERY: insert into rtest_order1 values (1);
QUERY: select * from rtest_order2;
a|b|c
-+-+-----------------------------------
1|1|rule 2 - this should run 1st
1|2|rule 4 - this should run 2nd
1|3|rule 3 - this should run 3rd or 4th
1|4|rule 1 - this should run 3rd or 4th
--
-- Check that the ordering of rules fired is correct
--
insert into rtest_order1 values (1);
select * from rtest_order2;
a | b | c
---+---+-------------------------------------
1 | 1 | rule 2 - this should run 1st
1 | 2 | rule 4 - this should run 2nd
1 | 3 | rule 3 - this should run 3rd or 4th
1 | 4 | rule 1 - this should run 3rd or 4th
(4 rows)
QUERY: insert into rtest_nothn1 values (1, 'want this');
QUERY: insert into rtest_nothn1 values (2, 'want this');
QUERY: insert into rtest_nothn1 values (10, 'don''t want this');
QUERY: insert into rtest_nothn1 values (19, 'don''t want this');
QUERY: insert into rtest_nothn1 values (20, 'want this');
QUERY: insert into rtest_nothn1 values (29, 'want this');
QUERY: insert into rtest_nothn1 values (30, 'don''t want this');
QUERY: insert into rtest_nothn1 values (39, 'don''t want this');
QUERY: insert into rtest_nothn1 values (40, 'want this');
QUERY: insert into rtest_nothn1 values (50, 'want this');
QUERY: insert into rtest_nothn1 values (60, 'want this');
QUERY: select * from rtest_nothn1;
a|b
--+---------
1|want this
2|want this
20|want this
29|want this
40|want this
50|want this
60|want this
--
-- Check if instead nothing w/without qualification works
--
insert into rtest_nothn1 values (1, 'want this');
insert into rtest_nothn1 values (2, 'want this');
insert into rtest_nothn1 values (10, 'don''t want this');
insert into rtest_nothn1 values (19, 'don''t want this');
insert into rtest_nothn1 values (20, 'want this');
insert into rtest_nothn1 values (29, 'want this');
insert into rtest_nothn1 values (30, 'don''t want this');
insert into rtest_nothn1 values (39, 'don''t want this');
insert into rtest_nothn1 values (40, 'want this');
insert into rtest_nothn1 values (50, 'want this');
insert into rtest_nothn1 values (60, 'want this');
select * from rtest_nothn1;
a | b
----+-----------
1 | want this
2 | want this
20 | want this
29 | want this
40 | want this
50 | want this
60 | want this
(7 rows)
QUERY: insert into rtest_nothn2 values (10, 'too small');
QUERY: insert into rtest_nothn2 values (50, 'too small');
QUERY: insert into rtest_nothn2 values (100, 'OK');
QUERY: insert into rtest_nothn2 values (200, 'OK');
QUERY: select * from rtest_nothn2;
a|b
-+-
insert into rtest_nothn2 values (10, 'too small');
insert into rtest_nothn2 values (50, 'too small');
insert into rtest_nothn2 values (100, 'OK');
insert into rtest_nothn2 values (200, 'OK');
select * from rtest_nothn2;
a | b
---+---
(0 rows)
QUERY: select * from rtest_nothn3;
a|b
---+--
100|OK
200|OK
select * from rtest_nothn3;
a | b
-----+----
100 | OK
200 | OK
(2 rows)
QUERY: delete from rtest_nothn1;
QUERY: delete from rtest_nothn2;
QUERY: delete from rtest_nothn3;
QUERY: insert into rtest_nothn4 values (1, 'want this');
QUERY: insert into rtest_nothn4 values (2, 'want this');
QUERY: insert into rtest_nothn4 values (10, 'don''t want this');
QUERY: insert into rtest_nothn4 values (19, 'don''t want this');
QUERY: insert into rtest_nothn4 values (20, 'want this');
QUERY: insert into rtest_nothn4 values (29, 'want this');
QUERY: insert into rtest_nothn4 values (30, 'don''t want this');
QUERY: insert into rtest_nothn4 values (39, 'don''t want this');
QUERY: insert into rtest_nothn4 values (40, 'want this');
QUERY: insert into rtest_nothn4 values (50, 'want this');
QUERY: insert into rtest_nothn4 values (60, 'want this');
QUERY: insert into rtest_nothn1 select * from rtest_nothn4;
QUERY: select * from rtest_nothn1;
a|b
--+---------
1|want this
2|want this
20|want this
29|want this
40|want this
50|want this
60|want this
delete from rtest_nothn1;
delete from rtest_nothn2;
delete from rtest_nothn3;
insert into rtest_nothn4 values (1, 'want this');
insert into rtest_nothn4 values (2, 'want this');
insert into rtest_nothn4 values (10, 'don''t want this');
insert into rtest_nothn4 values (19, 'don''t want this');
insert into rtest_nothn4 values (20, 'want this');
insert into rtest_nothn4 values (29, 'want this');
insert into rtest_nothn4 values (30, 'don''t want this');
insert into rtest_nothn4 values (39, 'don''t want this');
insert into rtest_nothn4 values (40, 'want this');
insert into rtest_nothn4 values (50, 'want this');
insert into rtest_nothn4 values (60, 'want this');
insert into rtest_nothn1 select * from rtest_nothn4;
select * from rtest_nothn1;
a | b
----+-----------
1 | want this
2 | want this
20 | want this
29 | want this
40 | want this
50 | want this
60 | want this
(7 rows)
QUERY: delete from rtest_nothn4;
QUERY: insert into rtest_nothn4 values (10, 'too small');
QUERY: insert into rtest_nothn4 values (50, 'too small');
QUERY: insert into rtest_nothn4 values (100, 'OK');
QUERY: insert into rtest_nothn4 values (200, 'OK');
QUERY: insert into rtest_nothn2 select * from rtest_nothn4;
QUERY: select * from rtest_nothn2;
a|b
-+-
delete from rtest_nothn4;
insert into rtest_nothn4 values (10, 'too small');
insert into rtest_nothn4 values (50, 'too small');
insert into rtest_nothn4 values (100, 'OK');
insert into rtest_nothn4 values (200, 'OK');
insert into rtest_nothn2 select * from rtest_nothn4;
select * from rtest_nothn2;
a | b
---+---
(0 rows)
QUERY: select * from rtest_nothn3;
a|b
---+--
100|OK
200|OK
select * from rtest_nothn3;
a | b
-----+----
100 | OK
200 | OK
(2 rows)
QUERY: create table rtest_view1 (a int4, b text, v bool);
QUERY: create table rtest_view2 (a int4);
QUERY: create table rtest_view3 (a int4, b text);
QUERY: create table rtest_view4 (a int4, b text, c int4);
QUERY: create view rtest_vview1 as select a, b from rtest_view1 X
create table rtest_view1 (a int4, b text, v bool);
create table rtest_view2 (a int4);
create table rtest_view3 (a int4, b text);
create table rtest_view4 (a int4, b text, c int4);
create view rtest_vview1 as select a, b from rtest_view1 X
where 0 < (select count(*) from rtest_view2 Y where Y.a = X.a);
QUERY: create view rtest_vview2 as select a, b from rtest_view1 where v;
QUERY: create view rtest_vview3 as select a, b from rtest_vview2 X
create view rtest_vview2 as select a, b from rtest_view1 where v;
create view rtest_vview3 as select a, b from rtest_vview2 X
where 0 < (select count(*) from rtest_view2 Y where Y.a = X.a);
QUERY: create view rtest_vview4 as select X.a, X.b, count(Y.a) as refcount
create view rtest_vview4 as select X.a, X.b, count(Y.a) as refcount
from rtest_view1 X, rtest_view2 Y
where X.a = Y.a
group by X.a, X.b;
QUERY: create function rtest_viewfunc1(int4) returns int4 as
create function rtest_viewfunc1(int4) returns int4 as
'select count(*) from rtest_view2 where a = $1'
language 'sql';
QUERY: create view rtest_vview5 as select a, b, rtest_viewfunc1(a) as refcount
create view rtest_vview5 as select a, b, rtest_viewfunc1(a) as refcount
from rtest_view1;
QUERY: insert into rtest_view1 values (1, 'item 1', 't');
QUERY: insert into rtest_view1 values (2, 'item 2', 't');
QUERY: insert into rtest_view1 values (3, 'item 3', 't');
QUERY: insert into rtest_view1 values (4, 'item 4', 'f');
QUERY: insert into rtest_view1 values (5, 'item 5', 't');
QUERY: insert into rtest_view1 values (6, 'item 6', 'f');
QUERY: insert into rtest_view1 values (7, 'item 7', 't');
QUERY: insert into rtest_view1 values (8, 'item 8', 't');
QUERY: insert into rtest_view2 values (2);
QUERY: insert into rtest_view2 values (2);
QUERY: insert into rtest_view2 values (4);
QUERY: insert into rtest_view2 values (5);
QUERY: insert into rtest_view2 values (7);
QUERY: insert into rtest_view2 values (7);
QUERY: insert into rtest_view2 values (7);
QUERY: insert into rtest_view2 values (7);
QUERY: select * from rtest_vview1;
a|b
-+------
2|item 2
4|item 4
5|item 5
7|item 7
insert into rtest_view1 values (1, 'item 1', 't');
insert into rtest_view1 values (2, 'item 2', 't');
insert into rtest_view1 values (3, 'item 3', 't');
insert into rtest_view1 values (4, 'item 4', 'f');
insert into rtest_view1 values (5, 'item 5', 't');
insert into rtest_view1 values (6, 'item 6', 'f');
insert into rtest_view1 values (7, 'item 7', 't');
insert into rtest_view1 values (8, 'item 8', 't');
insert into rtest_view2 values (2);
insert into rtest_view2 values (2);
insert into rtest_view2 values (4);
insert into rtest_view2 values (5);
insert into rtest_view2 values (7);
insert into rtest_view2 values (7);
insert into rtest_view2 values (7);
insert into rtest_view2 values (7);
select * from rtest_vview1;
a | b
---+--------
2 | item 2
4 | item 4
5 | item 5
7 | item 7
(4 rows)
QUERY: select * from rtest_vview2;
a|b
-+------
1|item 1
2|item 2
3|item 3
5|item 5
7|item 7
8|item 8
select * from rtest_vview2;
a | b
---+--------
1 | item 1
2 | item 2
3 | item 3
5 | item 5
7 | item 7
8 | item 8
(6 rows)
QUERY: select * from rtest_vview3;
a|b
-+------
2|item 2
5|item 5
7|item 7
select * from rtest_vview3;
a | b
---+--------
2 | item 2
5 | item 5
7 | item 7
(3 rows)
QUERY: select * from rtest_vview4;
a|b |refcount
-+------+--------
2|item 2| 2
4|item 4| 1
5|item 5| 1
7|item 7| 4
select * from rtest_vview4;
a | b | refcount
---+--------+----------
2 | item 2 | 2
4 | item 4 | 1
5 | item 5 | 1
7 | item 7 | 4
(4 rows)
QUERY: select * from rtest_vview5;
a|b |refcount
-+------+--------
1|item 1| 0
2|item 2| 2
3|item 3| 0
4|item 4| 1
5|item 5| 1
6|item 6| 0
7|item 7| 4
8|item 8| 0
select * from rtest_vview5;
a | b | refcount
---+--------+----------
1 | item 1 | 0
2 | item 2 | 2
3 | item 3 | 0
4 | item 4 | 1
5 | item 5 | 1
6 | item 6 | 0
7 | item 7 | 4
8 | item 8 | 0
(8 rows)
QUERY: insert into rtest_view3 select * from rtest_vview1 where a < 7;
QUERY: select * from rtest_view3;
a|b
-+------
2|item 2
4|item 4
5|item 5
insert into rtest_view3 select * from rtest_vview1 where a < 7;
select * from rtest_view3;
a | b
---+--------
2 | item 2
4 | item 4
5 | item 5
(3 rows)
QUERY: delete from rtest_view3;
QUERY: insert into rtest_view3 select * from rtest_vview2 where a != 5 and b !~ '2';
QUERY: select * from rtest_view3;
a|b
-+------
1|item 1
3|item 3
7|item 7
8|item 8
delete from rtest_view3;
insert into rtest_view3 select * from rtest_vview2 where a != 5 and b !~ '2';
select * from rtest_view3;
a | b
---+--------
1 | item 1
3 | item 3
7 | item 7
8 | item 8
(4 rows)
QUERY: delete from rtest_view3;
QUERY: insert into rtest_view3 select * from rtest_vview3;
QUERY: select * from rtest_view3;
a|b
-+------
2|item 2
5|item 5
7|item 7
delete from rtest_view3;
insert into rtest_view3 select * from rtest_vview3;
select * from rtest_view3;
a | b
---+--------
2 | item 2
5 | item 5
7 | item 7
(3 rows)
QUERY: delete from rtest_view3;
QUERY: insert into rtest_view4 select * from rtest_vview4 where 3 > refcount;
QUERY: select * from rtest_view4;
a|b |c
-+------+-
2|item 2|2
4|item 4|1
5|item 5|1
delete from rtest_view3;
insert into rtest_view4 select * from rtest_vview4 where 3 > refcount;
select * from rtest_view4;
a | b | c
---+--------+---
2 | item 2 | 2
4 | item 4 | 1
5 | item 5 | 1
(3 rows)
QUERY: delete from rtest_view4;
QUERY: insert into rtest_view4 select * from rtest_vview5 where a > 2 and refcount = 0;
QUERY: select * from rtest_view4;
a|b |c
-+------+-
3|item 3|0
6|item 6|0
8|item 8|0
delete from rtest_view4;
insert into rtest_view4 select * from rtest_vview5 where a > 2 and refcount = 0;
select * from rtest_view4;
a | b | c
---+--------+---
3 | item 3 | 0
6 | item 6 | 0
8 | item 8 | 0
(3 rows)
QUERY: delete from rtest_view4;
QUERY: create table rtest_comp (
delete from rtest_view4;
--
-- Test for computations in views
--
create table rtest_comp (
part text,
unit char(4),
size float
);
QUERY: create table rtest_unitfact (
create table rtest_unitfact (
unit char(4),
factor float
);
QUERY: create view rtest_vcomp as
create view rtest_vcomp as
select X.part, (X.size * Y.factor) as size_in_cm
from rtest_comp X, rtest_unitfact Y
where X.unit = Y.unit;
QUERY: insert into rtest_unitfact values ('m', 100.0);
QUERY: insert into rtest_unitfact values ('cm', 1.0);
QUERY: insert into rtest_unitfact values ('inch', 2.54);
QUERY: insert into rtest_comp values ('p1', 'm', 5.0);
QUERY: insert into rtest_comp values ('p2', 'm', 3.0);
QUERY: insert into rtest_comp values ('p3', 'cm', 5.0);
QUERY: insert into rtest_comp values ('p4', 'cm', 15.0);
QUERY: insert into rtest_comp values ('p5', 'inch', 7.0);
QUERY: insert into rtest_comp values ('p6', 'inch', 4.4);
QUERY: select * from rtest_vcomp order by part;
part|size_in_cm
----+----------
p1 | 500
p2 | 300
p3 | 5
p4 | 15
p5 | 17.78
p6 | 11.176
insert into rtest_unitfact values ('m', 100.0);
insert into rtest_unitfact values ('cm', 1.0);
insert into rtest_unitfact values ('inch', 2.54);
insert into rtest_comp values ('p1', 'm', 5.0);
insert into rtest_comp values ('p2', 'm', 3.0);
insert into rtest_comp values ('p3', 'cm', 5.0);
insert into rtest_comp values ('p4', 'cm', 15.0);
insert into rtest_comp values ('p5', 'inch', 7.0);
insert into rtest_comp values ('p6', 'inch', 4.4);
select * from rtest_vcomp order by part;
part | size_in_cm
------+------------
p1 | 500
p2 | 300
p3 | 5
p4 | 15
p5 | 17.78
p6 | 11.176
(6 rows)
QUERY: select * from rtest_vcomp where size_in_cm > 10.0 order by size_in_cm using >;
part|size_in_cm
----+----------
p1 | 500
p2 | 300
p5 | 17.78
p4 | 15
p6 | 11.176
select * from rtest_vcomp where size_in_cm > 10.0 order by size_in_cm using >;
part | size_in_cm
------+------------
p1 | 500
p2 | 300
p5 | 17.78
p4 | 15
p6 | 11.176
(5 rows)
QUERY: CREATE TABLE shoe_data (
shoename char(10),
sh_avail integer,
slcolor char(10),
slminlen float,
slmaxlen float,
slunit char(8)
--
-- In addition run the (slightly modified) queries from the
-- programmers manual section on the rule system.
--
CREATE TABLE shoe_data (
shoename char(10), -- primary key
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 (
sl_name char(10),
sl_avail integer,
sl_color char(10),
sl_len float,
sl_unit char(8)
CREATE TABLE shoelace_data (
sl_name char(10), -- primary key
sl_avail integer, -- available # of pairs
sl_color char(10), -- shoelace color
sl_len float, -- shoelace length
sl_unit char(8) -- length unit
);
QUERY: CREATE TABLE unit (
un_name char(8),
un_fact float
CREATE TABLE unit (
un_name char(8), -- the primary key
un_fact float -- factor to transform to cm
);
QUERY: CREATE VIEW shoe AS
CREATE VIEW shoe AS
SELECT sh.shoename,
sh.sh_avail,
sh.slcolor,
......@@ -879,7 +954,7 @@ QUERY: CREATE VIEW shoe AS
sh.slunit
FROM shoe_data sh, unit un
WHERE sh.slunit = un.un_name;
QUERY: CREATE VIEW shoelace AS
CREATE VIEW shoelace AS
SELECT s.sl_name,
s.sl_avail,
s.sl_color,
......@@ -888,7 +963,7 @@ QUERY: CREATE VIEW shoelace AS
s.sl_len * u.un_fact AS sl_len_cm
FROM shoelace_data s, unit u
WHERE s.sl_unit = u.un_name;
QUERY: CREATE VIEW shoe_ready AS
CREATE VIEW shoe_ready AS
SELECT rsh.shoename,
rsh.sh_avail,
rsl.sl_name,
......@@ -898,48 +973,52 @@ QUERY: CREATE VIEW shoe_ready AS
WHERE rsl.sl_color = rsh.slcolor
AND rsl.sl_len_cm >= rsh.slminlen_cm
AND rsl.sl_len_cm <= rsh.slmaxlen_cm;
QUERY: INSERT INTO unit VALUES ('cm', 1.0);
QUERY: INSERT INTO unit VALUES ('m', 100.0);
QUERY: INSERT INTO unit VALUES ('inch', 2.54);
QUERY: INSERT INTO shoe_data VALUES ('sh1', 2, 'black', 70.0, 90.0, 'cm');
QUERY: INSERT INTO shoe_data VALUES ('sh2', 0, 'black', 30.0, 40.0, 'inch');
QUERY: INSERT INTO shoe_data VALUES ('sh3', 4, 'brown', 50.0, 65.0, 'cm');
QUERY: INSERT INTO shoe_data VALUES ('sh4', 3, 'brown', 40.0, 50.0, 'inch');
QUERY: INSERT INTO shoelace_data VALUES ('sl1', 5, 'black', 80.0, 'cm');
QUERY: INSERT INTO shoelace_data VALUES ('sl2', 6, 'black', 100.0, 'cm');
QUERY: INSERT INTO shoelace_data VALUES ('sl3', 0, 'black', 35.0 , 'inch');
QUERY: INSERT INTO shoelace_data VALUES ('sl4', 8, 'black', 40.0 , 'inch');
QUERY: INSERT INTO shoelace_data VALUES ('sl5', 4, 'brown', 1.0 , 'm');
QUERY: INSERT INTO shoelace_data VALUES ('sl6', 0, 'brown', 0.9 , 'm');
QUERY: INSERT INTO shoelace_data VALUES ('sl7', 7, 'brown', 60 , 'cm');
QUERY: INSERT INTO shoelace_data VALUES ('sl8', 1, 'brown', 40 , 'inch');
QUERY: SELECT * FROM shoelace 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
sl3 | 0|black | 35|inch | 88.9
sl4 | 8|black | 40|inch | 101.6
sl5 | 4|brown | 1|m | 100
sl6 | 0|brown | 0.9|m | 90
sl7 | 7|brown | 60|cm | 60
sl8 | 1|brown | 40|inch | 101.6
INSERT INTO unit VALUES ('cm', 1.0);
INSERT INTO unit VALUES ('m', 100.0);
INSERT INTO unit VALUES ('inch', 2.54);
INSERT INTO shoe_data VALUES ('sh1', 2, 'black', 70.0, 90.0, 'cm');
INSERT INTO shoe_data VALUES ('sh2', 0, 'black', 30.0, 40.0, 'inch');
INSERT INTO shoe_data VALUES ('sh3', 4, 'brown', 50.0, 65.0, 'cm');
INSERT INTO shoe_data VALUES ('sh4', 3, 'brown', 40.0, 50.0, 'inch');
INSERT INTO shoelace_data VALUES ('sl1', 5, 'black', 80.0, 'cm');
INSERT INTO shoelace_data VALUES ('sl2', 6, 'black', 100.0, 'cm');
INSERT INTO shoelace_data VALUES ('sl3', 0, 'black', 35.0 , 'inch');
INSERT INTO shoelace_data VALUES ('sl4', 8, 'black', 40.0 , 'inch');
INSERT INTO shoelace_data VALUES ('sl5', 4, 'brown', 1.0 , 'm');
INSERT INTO shoelace_data VALUES ('sl6', 0, 'brown', 0.9 , 'm');
INSERT INTO shoelace_data VALUES ('sl7', 7, 'brown', 60 , 'cm');
INSERT INTO shoelace_data VALUES ('sl8', 1, 'brown', 40 , 'inch');
-- SELECTs in doc
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
sl3 | 0 | black | 35 | inch | 88.9
sl4 | 8 | black | 40 | inch | 101.6
sl5 | 4 | brown | 1 | m | 100
sl6 | 0 | brown | 0.9 | m | 90
sl7 | 7 | brown | 60 | cm | 60
sl8 | 1 | brown | 40 | inch | 101.6
(8 rows)
QUERY: SELECT * FROM shoe_ready WHERE total_avail >= 2;
shoename |sh_avail|sl_name |sl_avail|total_avail
----------+--------+----------+--------+-----------
sh1 | 2|sl1 | 5| 2
sh3 | 4|sl7 | 7| 4
SELECT * FROM shoe_ready WHERE total_avail >= 2;
shoename | sh_avail | sl_name | sl_avail | total_avail
------------+----------+------------+----------+-------------
sh1 | 2 | sl1 | 5 | 2
sh3 | 4 | sl7 | 7 | 4
(2 rows)
QUERY: CREATE TABLE shoelace_log (
sl_name char(10),
sl_avail integer,
log_who name,
log_when datetime
CREATE TABLE shoelace_log (
sl_name char(10), -- shoelace changed
sl_avail integer, -- new available value
log_who name, -- who did it
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
DO INSERT INTO shoelace_log VALUES (
NEW.sl_name,
......@@ -947,14 +1026,14 @@ QUERY: CREATE RULE log_shoelace AS ON UPDATE TO shoelace_data
'Al Bundy',
'epoch'::text
);
QUERY: UPDATE shoelace_data SET sl_avail = 6 WHERE sl_name = 'sl7';
QUERY: SELECT * FROM shoelace_log;
sl_name |sl_avail|log_who |log_when
----------+--------+--------+--------
sl7 | 6|Al Bundy|epoch
UPDATE shoelace_data SET sl_avail = 6 WHERE sl_name = 'sl7';
SELECT * FROM shoelace_log;
sl_name | sl_avail | log_who | log_when
------------+----------+----------+----------
sl7 | 6 | Al Bundy | epoch
(1 row)
QUERY: CREATE RULE shoelace_ins AS ON INSERT TO shoelace
CREATE RULE shoelace_ins AS ON INSERT TO shoelace
DO INSTEAD
INSERT INTO shoelace_data VALUES (
NEW.sl_name,
......@@ -962,7 +1041,7 @@ QUERY: CREATE RULE shoelace_ins AS ON INSERT TO shoelace
NEW.sl_color,
NEW.sl_len,
NEW.sl_unit);
QUERY: CREATE RULE shoelace_upd AS ON UPDATE TO shoelace
CREATE RULE shoelace_upd AS ON UPDATE TO shoelace
DO INSTEAD
UPDATE shoelace_data SET
sl_name = NEW.sl_name,
......@@ -971,154 +1050,157 @@ QUERY: CREATE RULE shoelace_upd AS ON UPDATE TO shoelace
sl_len = NEW.sl_len,
sl_unit = NEW.sl_unit
WHERE sl_name = OLD.sl_name;
QUERY: CREATE RULE shoelace_del AS ON DELETE TO shoelace
CREATE RULE shoelace_del AS ON DELETE TO shoelace
DO INSTEAD
DELETE FROM shoelace_data
WHERE sl_name = OLD.sl_name;
QUERY: CREATE TABLE shoelace_arrive (
CREATE TABLE shoelace_arrive (
arr_name char(10),
arr_quant integer
);
QUERY: CREATE TABLE shoelace_ok (
CREATE TABLE shoelace_ok (
ok_name char(10),
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
UPDATE shoelace SET
sl_avail = sl_avail + NEW.ok_quant
WHERE sl_name = NEW.ok_name;
QUERY: INSERT INTO shoelace_arrive VALUES ('sl3', 10);
QUERY: INSERT INTO shoelace_arrive VALUES ('sl6', 20);
QUERY: INSERT INTO shoelace_arrive VALUES ('sl8', 20);
QUERY: SELECT * FROM shoelace 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
sl3 | 0|black | 35|inch | 88.9
sl4 | 8|black | 40|inch | 101.6
sl5 | 4|brown | 1|m | 100
sl6 | 0|brown | 0.9|m | 90
sl7 | 6|brown | 60|cm | 60
sl8 | 1|brown | 40|inch | 101.6
INSERT INTO shoelace_arrive VALUES ('sl3', 10);
INSERT INTO shoelace_arrive VALUES ('sl6', 20);
INSERT INTO shoelace_arrive VALUES ('sl8', 20);
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
sl3 | 0 | black | 35 | inch | 88.9
sl4 | 8 | black | 40 | inch | 101.6
sl5 | 4 | brown | 1 | m | 100
sl6 | 0 | brown | 0.9 | m | 90
sl7 | 6 | brown | 60 | cm | 60
sl8 | 1 | brown | 40 | inch | 101.6
(8 rows)
QUERY: insert into shoelace_ok select * from shoelace_arrive;
QUERY: 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
sl3 | 10|black | 35|inch | 88.9
sl4 | 8|black | 40|inch | 101.6
sl5 | 4|brown | 1|m | 100
sl6 | 20|brown | 0.9|m | 90
sl7 | 6|brown | 60|cm | 60
sl8 | 21|brown | 40|inch | 101.6
insert into shoelace_ok select * from shoelace_arrive;
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
sl3 | 10 | black | 35 | inch | 88.9
sl4 | 8 | black | 40 | inch | 101.6
sl5 | 4 | brown | 1 | m | 100
sl6 | 20 | brown | 0.9 | m | 90
sl7 | 6 | brown | 60 | cm | 60
sl8 | 21 | brown | 40 | inch | 101.6
(8 rows)
QUERY: SELECT * FROM shoelace_log ORDER BY sl_name;
sl_name |sl_avail|log_who |log_when
----------+--------+--------+--------
sl3 | 10|Al Bundy|epoch
sl6 | 20|Al Bundy|epoch
sl7 | 6|Al Bundy|epoch
sl8 | 21|Al Bundy|epoch
SELECT * FROM shoelace_log ORDER BY sl_name;
sl_name | sl_avail | log_who | log_when
------------+----------+----------+----------
sl3 | 10 | Al Bundy | epoch
sl6 | 20 | Al Bundy | epoch
sl7 | 6 | Al Bundy | epoch
sl8 | 21 | Al Bundy | epoch
(4 rows)
QUERY: CREATE VIEW shoelace_obsolete AS
CREATE VIEW shoelace_obsolete AS
SELECT * FROM shoelace WHERE NOT EXISTS
(SELECT shoename FROM shoe WHERE slcolor = sl_color);
QUERY: CREATE VIEW shoelace_candelete AS
CREATE VIEW shoelace_candelete AS
SELECT * FROM shoelace_obsolete WHERE sl_avail = 0;
QUERY: insert into shoelace values ('sl9', 0, 'pink', 35.0, 'inch', 0.0);
QUERY: insert into shoelace values ('sl10', 1000, 'magenta', 40.0, 'inch', 0.0);
QUERY: SELECT * FROM shoelace_obsolete;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm
----------+--------+----------+------+--------+---------
sl9 | 0|pink | 35|inch | 88.9
sl10 | 1000|magenta | 40|inch | 101.6
insert into shoelace values ('sl9', 0, 'pink', 35.0, 'inch', 0.0);
insert into shoelace values ('sl10', 1000, 'magenta', 40.0, 'inch', 0.0);
SELECT * FROM shoelace_obsolete;
sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
------------+----------+------------+--------+----------+-----------
sl9 | 0 | pink | 35 | inch | 88.9
sl10 | 1000 | magenta | 40 | inch | 101.6
(2 rows)
QUERY: SELECT * FROM shoelace_candelete;
sl_name |sl_avail|sl_color |sl_len|sl_unit |sl_len_cm
----------+--------+----------+------+--------+---------
sl9 | 0|pink | 35|inch | 88.9
SELECT * FROM shoelace_candelete;
sl_name | sl_avail | sl_color | sl_len | sl_unit | sl_len_cm
------------+----------+------------+--------+----------+-----------
sl9 | 0 | pink | 35 | inch | 88.9
(1 row)
QUERY: DELETE FROM shoelace WHERE EXISTS
DELETE FROM shoelace WHERE EXISTS
(SELECT * FROM shoelace_candelete
WHERE sl_name = shoelace.sl_name);
QUERY: 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
sl10 | 1000|magenta | 40|inch | 101.6
sl2 | 6|black | 100|cm | 100
sl3 | 10|black | 35|inch | 88.9
sl4 | 8|black | 40|inch | 101.6
sl5 | 4|brown | 1|m | 100
sl6 | 20|brown | 0.9|m | 90
sl7 | 6|brown | 60|cm | 60
sl8 | 21|brown | 40|inch | 101.6
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
sl10 | 1000 | magenta | 40 | inch | 101.6
sl2 | 6 | black | 100 | cm | 100
sl3 | 10 | black | 35 | inch | 88.9
sl4 | 8 | black | 40 | inch | 101.6
sl5 | 4 | brown | 1 | m | 100
sl6 | 20 | brown | 0.9 | m | 90
sl7 | 6 | brown | 60 | cm | 60
sl8 | 21 | brown | 40 | inch | 101.6
(9 rows)
QUERY: SELECT viewname, definition FROM pg_views ORDER BY viewname;
viewname |definition
------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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_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_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"))))));
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_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_v1 |SELECT rtest_t1.a, rtest_t1.b FROM rtest_t1;
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_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_vview2 |SELECT rtest_view1.a, rtest_view1.b FROM rtest_view1 WHERE rtest_view1.v;
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_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_vview5 |SELECT rtest_view1.a, rtest_view1.b, rtest_viewfunc1(rtest_view1.a) AS refcount FROM rtest_view1;
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);
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));
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);
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;
--
-- Check that ruleutils are working
--
SELECT viewname, definition FROM pg_views ORDER BY viewname;
viewname | definition
--------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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_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_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"))))));
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_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_v1 | SELECT rtest_t1.a, rtest_t1.b FROM rtest_t1;
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_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_vview2 | SELECT rtest_view1.a, rtest_view1.b FROM rtest_view1 WHERE rtest_view1.v;
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_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_vview5 | SELECT rtest_view1.a, rtest_view1.b, rtest_viewfunc1(rtest_view1.a) AS refcount FROM rtest_view1;
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);
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));
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);
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)
QUERY: SELECT tablename, rulename, definition FROM pg_rules
SELECT tablename, rulename, definition FROM pg_rules
ORDER BY tablename, rulename;
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_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_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_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_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_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_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_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_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_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_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_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_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_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);
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_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_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_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_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_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_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_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_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_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_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_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_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_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);
(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);
QUERY: CREATE TEMP TABLE temptest(col int);
QUERY: CREATE INDEX i_temptest ON temptest(col);
QUERY: DROP INDEX i_temptest;
QUERY: DROP TABLE temptest;
QUERY: DROP INDEX i_temptest;
QUERY: DROP TABLE temptest;
QUERY: CREATE TABLE temptest(col int);
QUERY: INSERT INTO temptest VALUES (1);
QUERY: CREATE TEMP TABLE temptest(col int);
QUERY: INSERT INTO temptest VALUES (2);
QUERY: SELECT * FROM temptest;
col
---
2
--
-- TEMP
-- Test temp relations and indexes
--
-- test temp table/index masking
CREATE TABLE temptest(col int);
CREATE INDEX i_temptest ON temptest(col);
CREATE TEMP TABLE temptest(col int);
CREATE INDEX i_temptest ON temptest(col);
DROP INDEX i_temptest;
DROP TABLE temptest;
DROP INDEX i_temptest;
DROP TABLE temptest;
-- test temp table selects
CREATE TABLE temptest(col int);
INSERT INTO temptest VALUES (1);
CREATE TEMP TABLE temptest(col int);
INSERT INTO temptest VALUES (2);
SELECT * FROM temptest;
col
-----
2
(1 row)
QUERY: DROP TABLE temptest;
QUERY: SELECT * FROM temptest;
col
---
1
DROP TABLE temptest;
SELECT * FROM temptest;
col
-----
1
(1 row)
QUERY: DROP TABLE temptest;
QUERY: CREATE TEMP TABLE temptest(col int);
QUERY: SELECT * FROM temptest;
DROP TABLE temptest;
CREATE TEMP TABLE temptest(col int);
-- test temp table deletion
\c regression
SELECT * FROM temptest;
ERROR: Relation 'temptest' does not exist
QUERY: BEGIN;
QUERY: SELECT *
--
-- TRANSACTIONS
--
BEGIN;
SELECT *
INTO TABLE xacttest
FROM aggtest;
QUERY: INSERT INTO xacttest (a, b) VALUES (777, 777.777);
QUERY: END;
QUERY: SELECT a FROM xacttest WHERE a > 100;
a
---
777
INSERT INTO xacttest (a, b) VALUES (777, 777.777);
END;
-- should retrieve one value--
SELECT a FROM xacttest WHERE a > 100;
a
-----
777
(1 row)
QUERY: BEGIN;
QUERY: CREATE TABLE disappear (a int4);
QUERY: DELETE FROM aggtest;
QUERY: SELECT * FROM aggtest;
a|b
-+-
BEGIN;
CREATE TABLE disappear (a int4);
DELETE FROM aggtest;
-- should be empty
SELECT * FROM aggtest;
a | b
---+---
(0 rows)
QUERY: ABORT;
QUERY: SELECT oid FROM pg_class WHERE relname = 'disappear';
oid
---
ABORT;
-- should not exist
SELECT oid FROM pg_class WHERE relname = 'disappear';
oid
-----
(0 rows)
QUERY: SELECT * FROM aggtest;
a| b
---+-------
56| 7.8
100| 99.097
0|0.09561
42| 324.78
-- should have members again
SELECT * FROM aggtest;
a | b
-----+---------
56 | 7.8
100 | 99.097
0 | 0.09561
42 | 324.78
(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