Merge pull request !6114 from wangfeihuo/cherry-pick-1724395369
This commit is contained in:
opengauss_bot
2024-08-23 09:20:33 +00:00
committed by Gitee
3 changed files with 51 additions and 23 deletions

View File

@ -741,30 +741,37 @@ int base_yylex(YYSTYPE* lvalp, YYLTYPE* llocp, core_yyscan_t yyscanner)
break;
}
break;
case CURSOR:
GET_NEXT_TOKEN();
core_yystype_1 = cur_yylval; // the value of cursor
cur_yylloc_1 = cur_yylloc; // the lloc of cursor
next_token_1 = next_token; // the token after curosr
GET_NEXT_TOKEN();
core_yystype_2 = cur_yylval; // the value after cursor
cur_yylloc_2 = cur_yylloc; // the lloc after cursor
next_token_2 = next_token; // the token after after curosr
case CURSOR:
GET_NEXT_TOKEN();
core_yystype_1 = cur_yylval; // the value of cursor
cur_yylloc_1 = cur_yylloc; // the lloc of cursor
next_token_1 = next_token; // the token after curosr
if (next_token_1 != '(') {
/* save the lookahead token for next time */
SET_LOOKAHEAD_TOKEN();
/* and back up the output info to cur_token */
lvalp->core_yystype = cur_yylval;
*llocp = cur_yylloc;
} else {
GET_NEXT_TOKEN();
core_yystype_2 = cur_yylval; // the value after cursor
cur_yylloc_2 = cur_yylloc; // the lloc after cursor
next_token_2 = next_token; // the token after after curosr
if (next_token_1 == '(' && (is_select_stmt_definitely(next_token))) {
PARSE_CURSOR_PARENTHESES_AS_EXPR();
} else if (is_prefer_parse_cursor_parentheses_as_expr() && !is_cursor_function_exist()) {
PARSE_CURSOR_PARENTHESES_AS_EXPR();
} else {
PARSE_CURSOR_PARENTHESES_AS_FUNCTION();
}
if (t_thrd.proc->workingVersionNum < CURSOR_EXPRESSION_VERSION_NUMBER &&
cur_token == CURSOR_EXPR) {
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("Unsupported feature: cursor expression during the upgrade")));
}
break;
if (next_token_1 == '(' && (is_select_stmt_definitely(next_token))) {
PARSE_CURSOR_PARENTHESES_AS_EXPR();
} else if (is_prefer_parse_cursor_parentheses_as_expr() && !is_cursor_function_exist()) {
PARSE_CURSOR_PARENTHESES_AS_EXPR();
} else {
PARSE_CURSOR_PARENTHESES_AS_FUNCTION();
}
if (t_thrd.proc->workingVersionNum < CURSOR_EXPRESSION_VERSION_NUMBER &&
cur_token == CURSOR_EXPR) {
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("Unsupported feature: cursor expression during the upgrade")));
}
}
break;
default:
break;
}

View File

@ -978,7 +978,20 @@ NOTICE:
CONTEXT: PL/pgSQL function inline_code_block line 10 at FETCH
NOTICE: employee_name : zhangsan
set enable_auto_explain = off;
create table abort_test(cid int,fid int);
-- expect error
start transaction;
cursor 'abort' for select * from abort_test order by 1;
ERROR: syntax error at or near "'abort'"
LINE 1: cursor 'abort' for select * from abort_test order by 1;
^
close 'abort';
ERROR: syntax error at or near "'abort'"
LINE 1: close 'abort';
^
commit;
-- clean
drop table abort_test;
drop table test_insert;
drop procedure pro_cursor_0011_02;
drop table t_cursor_0011_01;

View File

@ -550,7 +550,15 @@ END;
/
set enable_auto_explain = off;
create table abort_test(cid int,fid int);
-- expect error
start transaction;
cursor 'abort' for select * from abort_test order by 1;
close 'abort';
commit;
-- clean
drop table abort_test;
drop table test_insert;
drop procedure pro_cursor_0011_02;
drop table t_cursor_0011_01;