Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4097233

Browse files
committed
Provide query source text when parsing a SQL-standard function body.
Without this, we lose error cursor positions, as shown in themodified regression test result.Discussion:https://postgr.es/m/2197698.1617984583@sss.pgh.pa.us
1 parent83efce7 commit4097233

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

‎src/backend/commands/functioncmds.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,9 @@ static void
852852
interpret_AS_clause(OidlanguageOid,constchar*languageName,
853853
char*funcname,List*as,Node*sql_body_in,
854854
List*parameterTypes,List*inParameterNames,
855-
char**prosrc_str_p,char**probin_str_p,Node**sql_body_out)
855+
char**prosrc_str_p,char**probin_str_p,
856+
Node**sql_body_out,
857+
constchar*queryString)
856858
{
857859
if (!sql_body_in&& !as)
858860
ereport(ERROR,
@@ -929,6 +931,7 @@ interpret_AS_clause(Oid languageOid, const char *languageName,
929931
Query*q;
930932
ParseState*pstate=make_parsestate(NULL);
931933

934+
pstate->p_sourcetext=queryString;
932935
sql_fn_parser_setup(pstate,pinfo);
933936
q=transformStmt(pstate,stmt);
934937
if (q->commandType==CMD_UTILITY)
@@ -947,13 +950,15 @@ interpret_AS_clause(Oid languageOid, const char *languageName,
947950
Query*q;
948951
ParseState*pstate=make_parsestate(NULL);
949952

953+
pstate->p_sourcetext=queryString;
950954
sql_fn_parser_setup(pstate,pinfo);
951955
q=transformStmt(pstate,sql_body_in);
952956
if (q->commandType==CMD_UTILITY)
953957
ereport(ERROR,
954958
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
955959
errmsg("%s is not yet supported in unquoted SQL function body",
956960
GetCommandTagName(CreateCommandTag(q->utilityStmt))));
961+
free_parsestate(pstate);
957962

958963
*sql_body_out= (Node*)q;
959964
}
@@ -1220,7 +1225,8 @@ CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt)
12201225

12211226
interpret_AS_clause(languageOid,language,funcname,as_clause,stmt->sql_body,
12221227
parameterTypes_list,inParameterNames_list,
1223-
&prosrc_str,&probin_str,&prosqlbody);
1228+
&prosrc_str,&probin_str,&prosqlbody,
1229+
pstate->p_sourcetext);
12241230

12251231
/*
12261232
* Set default values for COST and ROWS depending on other parameters;

‎src/test/regress/expected/create_function_3.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ CREATE FUNCTION functest_S_xx(x date) RETURNS boolean
295295
LANGUAGE SQL
296296
RETURN x > 1;
297297
ERROR: operator does not exist: date > integer
298+
LINE 3: RETURN x > 1;
299+
^
298300
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
299301
-- tricky parsing
300302
CREATE FUNCTION functest_S_15(x int) RETURNS boolean

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp