diff --git a/src/common/backend/parser/gram.y b/src/common/backend/parser/gram.y index 5e585ea305193e87059419efd217422e2765addf..e84128a51a8e3d5efead386ff7061e82f3025609 100644 --- a/src/common/backend/parser/gram.y +++ b/src/common/backend/parser/gram.y @@ -11659,11 +11659,15 @@ CreateTrigStmt: { if ($2 != false) { - parser_yyerror("syntax error found"); + ereport(errstate, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error."))); } if ($3 != NULL) { - parser_yyerror("only support definer in B compatibility database and B syntax"); + ereport(errstate, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("only support definer in B compatibility database and B syntax"))); } CreateTrigStmt *n = makeNode(CreateTrigStmt); n->definer = $3; @@ -11723,15 +11727,20 @@ CreateTrigStmt: u_sess->parser_cxt.isCreateFuncOrProc = true; } subprogram_body { - if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT || $2 != false) + if ($2 != false) { - parser_yyerror("only support definer, trigger_order, subprogram_body in B compatibility database"); + ereport(errstate, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error."))); } - CreateTrigStmt *n = makeNode(CreateTrigStmt); - if ($2 != false) + if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT) { - parser_yyerror("syntax error found"); + ereport(errstate, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("Current syntax is supported only in B compatibility database"))); } + CreateTrigStmt *n = makeNode(CreateTrigStmt); + n->definer = $3; n->if_not_exists = false; n->trigname = $5; @@ -11761,15 +11770,20 @@ CreateTrigStmt: u_sess->parser_cxt.isCreateFuncOrProc = true; } subprogram_body { - if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT) + if ($2 != false) { - parser_yyerror("only support definer, if not exists, trigger_order, subprogram_body in B compatibility database"); + ereport(errstate, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("syntax error."))); } - CreateTrigStmt *n = makeNode(CreateTrigStmt); - if ($2 != false) + if (u_sess->attr.attr_sql.sql_compatibility != B_FORMAT) { - parser_yyerror("syntax error"); + ereport(errstate, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("Current syntax is supported only in B compatibility database"))); } + CreateTrigStmt *n = makeNode(CreateTrigStmt); + n->definer = $3; n->if_not_exists = true; n->trigname = $8; diff --git a/src/test/regress/expected/mysql_syntax.out b/src/test/regress/expected/mysql_syntax.out index 47ea7ff96ba281f386ce9f77317954dfad05b64a..2fdde30a612d647aa626e62ea4b20173fcda4c72 100644 --- a/src/test/regress/expected/mysql_syntax.out +++ b/src/test/regress/expected/mysql_syntax.out @@ -3,6 +3,28 @@ drop database if exists db_mysql; NOTICE: database "db_mysql" does not exist, skipping create database db_mysql dbcompatibility 'B'; +drop database if exists db_td; +NOTICE: database "db_td" does not exist, skipping +create database db_td dbcompatibility='C'; +\c db_td +create table animals (id int, name char(30)); +create table food (id int, foodtype varchar(32), remark varchar(32), time_flag timestamp); +create trigger animal_trigger1 +after insert on animals +for each row +begin + insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now()); +end; +/ +ERROR: Current syntax is supported only in B compatibility database +create or replace trigger animal_trigger1 +after insert on animals +for each row +begin + insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now()); +end; +/ +ERROR: syntax error. \c db_mysql create table t (id int); create table t1 (id int); @@ -49,6 +71,14 @@ begin insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now()); end; / +create or replace trigger animal_trigger1 +after insert on animals +for each row +begin + insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now()); +end; +/ +ERROR: syntax error. --different type trigger follows|precedes create trigger animal_trigger2 before insert on animals @@ -448,6 +478,7 @@ ERROR: drop trigger without table name only support in B-format database drop trigger if exists animal_trigger1; ERROR: drop trigger without table name only support in B-format database drop database db_mysql; +drop database db_td; -- test declare condition in other compatibility create or replace procedure test_condition_1 as declare diff --git a/src/test/regress/sql/mysql_syntax.sql b/src/test/regress/sql/mysql_syntax.sql index 09c9e78c91dfdccd1f1e2c441f8383821b0c5814..6759fd520217dbec3da38d7050f813451fdc938d 100644 --- a/src/test/regress/sql/mysql_syntax.sql +++ b/src/test/regress/sql/mysql_syntax.sql @@ -2,6 +2,28 @@ -- test mysql compatibility trigger drop database if exists db_mysql; create database db_mysql dbcompatibility 'B'; +drop database if exists db_td; +create database db_td dbcompatibility='C'; + +\c db_td +create table animals (id int, name char(30)); +create table food (id int, foodtype varchar(32), remark varchar(32), time_flag timestamp); + +create trigger animal_trigger1 +after insert on animals +for each row +begin + insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now()); +end; +/ + +create or replace trigger animal_trigger1 +after insert on animals +for each row +begin + insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now()); +end; +/ \c db_mysql create table t (id int); create table t1 (id int); @@ -49,6 +71,14 @@ begin end; / +create or replace trigger animal_trigger1 +after insert on animals +for each row +begin + insert into food(id, foodtype, remark, time_flag) values (1,'ice cream', 'sdsdsdsd', now()); +end; +/ + --different type trigger follows|precedes create trigger animal_trigger2 @@ -343,6 +373,7 @@ call test_condition_1(); drop trigger animal_trigger1; drop trigger if exists animal_trigger1; drop database db_mysql; +drop database db_td; -- test declare condition in other compatibility create or replace procedure test_condition_1 as