Skip to content

Commit 28fc5d7

Browse files
Jan WieckJan Wieck
authored andcommitted
Reenabled parentheses for grouping multiple rule actions and
added this syntax to rules regression test so it will show up if someone breaks it again. Jan
1 parent ef590e1 commit 28fc5d7

File tree

3 files changed

+34
-37
lines changed

3 files changed

+34
-37
lines changed

src/backend/parser/gram.y

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.52 1999/02/06 20:27:34 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.53 1999/02/07 19:02:19 wieck Exp $
1414
*
1515
* HISTORY
1616
* AUTHOR DATE MAJOR EVENT
@@ -132,7 +132,7 @@ Oid param_type(int t); /* used in parse_expr.c */
132132
CreatedbStmt, DestroydbStmt, VacuumStmt, CursorStmt, SubSelect,
133133
UpdateStmt, InsertStmt, select_w_o_sort, SelectStmt, NotifyStmt, DeleteStmt,
134134
ClusterStmt, ExplainStmt, VariableSetStmt, VariableShowStmt, VariableResetStmt,
135-
CreateUserStmt, AlterUserStmt, DropUserStmt
135+
CreateUserStmt, AlterUserStmt, DropUserStmt, RuleActionStmt
136136

137137
%type <str> opt_database1, opt_database2, location, encoding
138138

@@ -163,7 +163,7 @@ Oid param_type(int t); /* used in parse_expr.c */
163163
result, relation_name_list, OptTableElementList,
164164
OptInherit, definition,
165165
opt_with, func_args, func_args_list,
166-
oper_argtypes, OptStmtList, OptStmtBlock, OptStmtMulti,
166+
oper_argtypes, RuleActionList, RuleActionBlock, RuleActionMulti,
167167
opt_column_list, columnList, opt_va_list, va_list,
168168
sort_clause, sortby_list, index_params, index_list, name_list,
169169
from_clause, from_list, opt_array_bounds, nest_array_bounds,
@@ -2058,7 +2058,7 @@ opt_column: COLUMN { $$ = COLUMN; }
20582058
RuleStmt: CREATE RULE name AS
20592059
{ QueryIsRule=TRUE; }
20602060
ON event TO event_object where_clause
2061-
DO opt_instead OptStmtList
2061+
DO opt_instead RuleActionList
20622062
{
20632063
RuleStmt *n = makeNode(RuleStmt);
20642064
n->rulename = $3;
@@ -2071,34 +2071,31 @@ RuleStmt: CREATE RULE name AS
20712071
}
20722072
;
20732073

2074-
OptStmtList: NOTHING { $$ = NIL; }
2075-
| OptimizableStmt { $$ = lcons($1, NIL); }
2076-
| '[' OptStmtBlock ']' { $$ = $2; }
2077-
/***S*I*D***/
2078-
/* We comment this out because it produces a shift / reduce conflict
2079-
* with the select_w_o_sort rule */
2080-
/* | '(' OptStmtBlock ')' { $$ = $2; } */
2074+
RuleActionList: NOTHING { $$ = NIL; }
2075+
| SelectStmt { $$ = lcons($1, NIL); }
2076+
| RuleActionStmt { $$ = lcons($1, NIL); }
2077+
| '[' RuleActionBlock ']' { $$ = $2; }
2078+
| '(' RuleActionBlock ')' { $$ = $2; }
20812079
;
20822080

2083-
OptStmtBlock: OptStmtMulti
2084-
{ $$ = $1; }
2085-
| OptimizableStmt
2086-
{ $$ = lcons($1, NIL); }
2081+
RuleActionBlock: RuleActionMulti { $$ = $1; }
2082+
| RuleActionStmt { $$ = lcons($1, NIL); }
20872083
;
20882084

2089-
OptStmtMulti: OptStmtMulti OptimizableStmt ';'
2085+
RuleActionMulti: RuleActionMulti RuleActionStmt
20902086
{ $$ = lappend($1, $2); }
2091-
/***S*I***/
2092-
/* We comment the next rule because it seems to be redundant
2093-
* and produces 16 shift/reduce conflicts with the new SelectStmt rule
2094-
* needed for EXCEPT and INTERSECT. So far I did not notice any
2095-
* violations by removing the rule! */
2096-
/* | OptStmtMulti OptimizableStmt
2097-
{ $$ = lappend($1, $2); } */
2098-
| OptimizableStmt ';'
2087+
| RuleActionMulti RuleActionStmt ';'
2088+
{ $$ = lappend($1, $2); }
2089+
| RuleActionStmt ';'
20992090
{ $$ = lcons($1, NIL); }
21002091
;
21012092

2093+
RuleActionStmt: InsertStmt
2094+
| UpdateStmt
2095+
| DeleteStmt
2096+
| NotifyStmt
2097+
;
2098+
21022099
event_object: relation_name '.' attr_name
21032100
{
21042101
$$ = makeNode(Attr);

src/test/regress/expected/rules.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ QUERY: create table rtest_system (sysname text, sysdesc text);
1313
QUERY: create table rtest_interface (sysname text, ifname text);
1414
QUERY: create table rtest_person (pname text, pdesc text);
1515
QUERY: create table rtest_admin (pname text, sysname text);
16-
QUERY: create rule rtest_sys_upd1 as on update to rtest_system do
16+
QUERY: create rule rtest_sys_upd as on update to rtest_system do (
1717
update rtest_interface set sysname = new.sysname
1818
where sysname = current.sysname;
19-
QUERY: create rule rtest_sys_upd2 as on update to rtest_system do
2019
update rtest_admin set sysname = new.sysname
21-
where sysname = current.sysname;
22-
QUERY: create rule rtest_sys_del1 as on delete to rtest_system do
20+
where sysname = current.sysname
21+
);
22+
QUERY: create rule rtest_sys_del as on delete to rtest_system do (
2323
delete from rtest_interface where sysname = current.sysname;
24-
QUERY: create rule rtest_sys_del2 as on delete to rtest_system do
2524
delete from rtest_admin where sysname = current.sysname;
25+
);
2626
QUERY: create rule rtest_pers_upd as on update to rtest_person do
2727
update rtest_admin set pname = new.pname where pname = current.pname;
2828
QUERY: create rule rtest_pers_del as on delete to rtest_person do

src/test/regress/sql/rules.sql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ create rule rtest_v1_del as on delete to rtest_v1 do instead
2424
-- Tables and rules for the constraint update/delete test
2525
--
2626
-- Note:
27-
-- psql prevents from putting colons into brackets as
28-
-- required for multi action rules. So we define single
29-
-- rules for each action required for now
27+
-- Now that we have multiple action rule support, we check
28+
-- both possible syntaxes to define them (The last action
29+
-- can but must not have a semicolon at the end).
3030
--
3131
create table rtest_system (sysname text, sysdesc text);
3232
create table rtest_interface (sysname text, ifname text);
3333
create table rtest_person (pname text, pdesc text);
3434
create table rtest_admin (pname text, sysname text);
3535

36-
create rule rtest_sys_upd1 as on update to rtest_system do
36+
create rule rtest_sys_upd as on update to rtest_system do (
3737
update rtest_interface set sysname = new.sysname
3838
where sysname = current.sysname;
39-
create rule rtest_sys_upd2 as on update to rtest_system do
4039
update rtest_admin set sysname = new.sysname
41-
where sysname = current.sysname;
40+
where sysname = current.sysname
41+
);
4242

43-
create rule rtest_sys_del1 as on delete to rtest_system do
43+
create rule rtest_sys_del as on delete to rtest_system do (
4444
delete from rtest_interface where sysname = current.sysname;
45-
create rule rtest_sys_del2 as on delete to rtest_system do
4645
delete from rtest_admin where sysname = current.sysname;
46+
);
4747

4848
create rule rtest_pers_upd as on update to rtest_person do
4949
update rtest_admin set pname = new.pname where pname = current.pname;

0 commit comments

Comments
 (0)