diff --git a/doc/src/sgml/alter_rule.sgmlin b/doc/src/sgml/alter_rule.sgmlin new file mode 100644 index 000000000..75fb7cac1 --- /dev/null +++ b/doc/src/sgml/alter_rule.sgmlin @@ -0,0 +1,16 @@ + + +ALTER RULE +7 +SQL - Language Statements + + +ALTER RULE +change the definition of a rule + + + +ALTER RULE name ON table_name RENAME TO new_name + + + diff --git a/doc/src/sgml/create_rule.sgmlin b/doc/src/sgml/create_rule.sgmlin new file mode 100644 index 000000000..21c432aed --- /dev/null +++ b/doc/src/sgml/create_rule.sgmlin @@ -0,0 +1,23 @@ + + +ALTER TABLE +7 +SQL - Language Statements + + +CREATE RULE +define a new rewrite rule + + + +CREATE [ OR REPLACE ] RULE name AS ON event + TO table_name [ WHERE condition ] + DO [ ALSO | INSTEAD ] { NOTHING | command | ( command ; command ... ) } + +where event can be one of: + + SELECT | INSERT | UPDATE | DELETE + + + + diff --git a/doc/src/sgml/drop_rule.sgmlin b/doc/src/sgml/drop_rule.sgmlin new file mode 100644 index 000000000..8affa0fa8 --- /dev/null +++ b/doc/src/sgml/drop_rule.sgmlin @@ -0,0 +1,16 @@ + + +ALTER TABLE +7 +SQL - Language Statements + + +DROP RULE +remove a rewrite rule + + + +DROP RULE [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ] + + + diff --git a/doc/src/sgml/ref/allfiles.sgmlin b/doc/src/sgml/ref/allfiles.sgmlin index e0ee99a52..a6e38d9b3 100644 --- a/doc/src/sgml/ref/allfiles.sgmlin +++ b/doc/src/sgml/ref/allfiles.sgmlin @@ -42,6 +42,7 @@ Complete list of usable sgml source files in this directory. + diff --git a/doc/src/sgml/ref/alter_table.sgmlin b/doc/src/sgml/ref/alter_table.sgmlin index 894c02f14..0c8a85dce 100755 --- a/doc/src/sgml/ref/alter_table.sgmlin +++ b/doc/src/sgml/ref/alter_table.sgmlin @@ -45,10 +45,15 @@ column_clause | ENABLE TRIGGER [ trigger_name | ALL | USER ] | ENABLE REPLICA TRIGGER trigger_name | ENABLE ALWAYS TRIGGER trigger_name + | DISABLE RULE rewrite_rule_name + | ENABLE RULE rewrite_rule_name + | ENABLE REPLICA RULE rewrite_rule_name + | ENABLE ALWAYS RULE rewrite_rule_name | ENABLE ROW LEVEL SECURITY | DISABLE ROW LEVEL SECURITY | FORCE ROW LEVEL SECURITY | NO FORCE ROW LEVEL SECURITY + | REPLICA IDENTITY {DEFAULT | USING INDEX index_name | FULL | NOTHING} where column_clause can be: ADD [ COLUMN ] column_name data_type [ compress_mode ] [ COLLATE collation ] [ column_constraint [ ... ] ] | MODIFY column_name data_type diff --git a/src/test/regress/expected/alter_table_000.out b/src/test/regress/expected/alter_table_000.out index a3872a915..45a617a40 100644 --- a/src/test/regress/expected/alter_table_000.out +++ b/src/test/regress/expected/alter_table_000.out @@ -41,10 +41,15 @@ column_clause | ENABLE TRIGGER [ trigger_name | ALL | USER ] | ENABLE REPLICA TRIGGER trigger_name | ENABLE ALWAYS TRIGGER trigger_name + | DISABLE RULE rewrite_rule_name + | ENABLE RULE rewrite_rule_name + | ENABLE REPLICA RULE rewrite_rule_name + | ENABLE ALWAYS RULE rewrite_rule_name | ENABLE ROW LEVEL SECURITY | DISABLE ROW LEVEL SECURITY | FORCE ROW LEVEL SECURITY | NO FORCE ROW LEVEL SECURITY + | REPLICA IDENTITY {DEFAULT | USING INDEX index_name | FULL | NOTHING} where column_clause can be: ADD [ COLUMN ] column_name data_type [ compress_mode ] [ COLLATE collation ] [ column_constraint [ ... ] ] | MODIFY column_name data_type diff --git a/src/test/regress/expected/rangefuncs.out b/src/test/regress/expected/rangefuncs.out index f207de763..d75c2b253 100644 --- a/src/test/regress/expected/rangefuncs.out +++ b/src/test/regress/expected/rangefuncs.out @@ -825,9 +825,11 @@ select * from tt order by 1, 2; -- note that nextval() gets executed a second time in the rule expansion, -- which is expected. select * from tt_log order by 1, 2; - f1 | data -----+------ -(0 rows) + f1 | data +----+--------- + | barlog + | foollog +(2 rows) -- test case for a whole-row-variable bug create function foo1(n integer, out a text, out b text) diff --git a/src/test/regress/expected/subselect_part1.out b/src/test/regress/expected/subselect_part1.out index 962329715..a7851dbc9 100644 --- a/src/test/regress/expected/subselect_part1.out +++ b/src/test/regress/expected/subselect_part1.out @@ -422,12 +422,11 @@ create rule shipped_view_insert as on insert to shipped_view do instead insert into parts (partnum, cost) values (1, 1234.56); insert into shipped_view (ordnum, partnum, value) values (0, 1, (select cost from parts where partnum = '1')); -ERROR: cannot insert into view "shipped_view" -HINT: You need an unconditional ON INSERT DO INSTEAD rule or an INSTEAD OF INSERT trigger. select * from shipped_view; - ttype | ordnum | partnum | value --------+--------+---------+------- -(0 rows) + ttype | ordnum | partnum | value +-------+--------+---------+--------- + wt | 0 | 1 | 1234.56 +(1 row) create rule shipped_view_update as on update to shipped_view do instead update shipped set partnum = new.partnum, value = new.value @@ -436,12 +435,11 @@ update shipped_view set value = 11 from int4_tbl a join int4_tbl b on (a.f1 = (select f1 from int4_tbl c where c.f1=b.f1)) where ordnum = a.f1; -ERROR: cannot update view "shipped_view" -HINT: You need an unconditional ON UPDATE DO INSTEAD rule or an INSTEAD OF UPDATE trigger. select * from shipped_view; ttype | ordnum | partnum | value -------+--------+---------+------- -(0 rows) + wt | 0 | 1 | 11 +(1 row) select f1, ss1 as relabel from (select *, (select sum(f1) from int4_tbl b where f1 >= a.f1) as ss1 diff --git a/src/test/regress/expected/with.out b/src/test/regress/expected/with.out index d30060329..3d94e5814 100644 --- a/src/test/regress/expected/with.out +++ b/src/test/regress/expected/with.out @@ -1462,6 +1462,12 @@ WITH t AS ( ) SELECT * FROM t; a +---- + 42 +(1 row) + +SELECT * FROM y order by 1; + a ---- 0 1 @@ -1470,19 +1476,15 @@ SELECT * FROM t; 4 5 6 - 11 7 - 12 8 - 13 9 + 11 + 12 + 13 14 -(14 rows) - -SELECT * FROM y order by 1; - a ---- -(0 rows) + 42 +(15 rows) DROP RULE y_rule ON y; -- check merging of outer CTE with CTE in a rule action @@ -1514,18 +1516,21 @@ WITH t1 AS ( DELETE FROM bug6051 RETURNING * ) INSERT INTO bug6051 SELECT * FROM t1; SELECT * FROM bug6051 ORDER BY 1; i +--- +(0 rows) + +SELECT * FROM bug6051_2 ORDER BY 1; + i --- 1 2 3 (3 rows) -SELECT * FROM bug6051_2 ORDER BY 1; - i ---- -(0 rows) - -- a truly recursive CTE in the same list +DROP TABLE y; +CREATE TABLE y (a INTEGER PRIMARY KEY INITIALLY DEFERRED); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "y_pkey" for table "y" WITH RECURSIVE t(a) AS ( SELECT 0 UNION ALL @@ -1890,11 +1895,7 @@ WITH t AS ( INSERT INTO y VALUES(0) ) VALUES(FALSE); - column1 ---------- - f -(1 row) - +ERROR: conditional DO INSTEAD rules are not supported for data-modifying statements in WITH DROP RULE y_rule ON y; -- check cte replace when pulling up -- case 1: exists/any sublink diff --git a/src/test/regress/expected/xc_alter_table.out b/src/test/regress/expected/xc_alter_table.out index 0d4d889f4..506930fe1 100644 --- a/src/test/regress/expected/xc_alter_table.out +++ b/src/test/regress/expected/xc_alter_table.out @@ -228,9 +228,10 @@ SELECT b FROM xc_alter_table_3 WHERE a = 11; EXECUTE xc_alter_table_delete(11); SELECT b FROM xc_alter_table_3 WHERE a = 11 or a = 12; - b ---- -(0 rows) + b +----- + nnn +(1 row) EXECUTE xc_alter_table_delete(12); SELECT count(*), sum(a), avg(a) FROM xc_alter_table_3; -- Check on tuple presence @@ -261,9 +262,10 @@ SELECT b FROM xc_alter_table_3 WHERE a = 11; EXECUTE xc_alter_table_delete(11); SELECT b FROM xc_alter_table_3 WHERE a = 11 or a = 12; - b ---- -(0 rows) + b +----- + nnn +(1 row) EXECUTE xc_alter_table_delete(12); SELECT count(*), sum(a), avg(a) FROM xc_alter_table_3; -- Check on tuple presence @@ -294,9 +296,10 @@ SELECT b FROM xc_alter_table_3 WHERE a = 11; EXECUTE xc_alter_table_delete(11); SELECT b FROM xc_alter_table_3 WHERE a = 11 or a = 12; - b ---- -(0 rows) + b +----- + nnn +(1 row) EXECUTE xc_alter_table_delete(12); SELECT count(*), sum(a), avg(a) FROM xc_alter_table_3; -- Check on tuple presence @@ -327,9 +330,10 @@ SELECT b FROM xc_alter_table_3 WHERE a = 11; EXECUTE xc_alter_table_delete(11); SELECT b FROM xc_alter_table_3 WHERE a = 11 or a = 12; - b ---- -(0 rows) + b +----- + nnn +(1 row) EXECUTE xc_alter_table_delete(12); SELECT count(*), sum(a), avg(a) FROM xc_alter_table_3; -- Check on tuple presence @@ -360,9 +364,10 @@ SELECT b FROM xc_alter_table_3 WHERE a = 11; EXECUTE xc_alter_table_delete(11); SELECT b FROM xc_alter_table_3 WHERE a = 11 or a = 12; - b ---- -(0 rows) + b +----- + nnn +(1 row) EXECUTE xc_alter_table_delete(12); -- Index and redistribution @@ -395,9 +400,10 @@ SELECT b FROM xc_alter_table_3 WHERE a = 11; EXECUTE xc_alter_table_delete(11); SELECT b FROM xc_alter_table_3 WHERE a = 11 or a = 12; - b ---- -(0 rows) + b +----- + nnn +(1 row) EXECUTE xc_alter_table_delete(12); -- Add column on table diff --git a/src/test/regress/sql/with.sql b/src/test/regress/sql/with.sql index 99ef63b92..d75994044 100644 --- a/src/test/regress/sql/with.sql +++ b/src/test/regress/sql/with.sql @@ -748,6 +748,8 @@ SELECT * FROM bug6051 ORDER BY 1; SELECT * FROM bug6051_2 ORDER BY 1; -- a truly recursive CTE in the same list +DROP TABLE y; +CREATE TABLE y (a INTEGER PRIMARY KEY INITIALLY DEFERRED); WITH RECURSIVE t(a) AS ( SELECT 0 UNION ALL