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

Commit59a4a57

Browse files
committed
Make plpgsql complain about conflicting IN and OUT parameter names.
The core CREATE FUNCTION code only enforces that IN parameter names arenon-duplicate, and that OUT parameter names are separately non-duplicate.This is because some function languages might not have any confusionbetween the two. But in plpgsql, such names are all in the same namespace,so we'd better disallow it.Per a recent complaint from Dan S. Not back-patching since this is a smallissue and the change could cause unexpected failures if we started toenforce it in a minor release.
1 parent34be83b commit59a4a57

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

‎src/pl/plpgsql/src/pl_comp.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static PLpgSQL_function *do_compile(FunctionCallInfo fcinfo,
9595
PLpgSQL_func_hashkey*hashkey,
9696
boolforValidator);
9797
staticvoidplpgsql_compile_error_callback(void*arg);
98+
staticvoidadd_parameter_name(intitemtype,intitemno,constchar*name);
9899
staticvoidadd_dummy_return(PLpgSQL_function*function);
99100
staticNode*plpgsql_pre_column_ref(ParseState*pstate,ColumnRef*cref);
100101
staticNode*plpgsql_post_column_ref(ParseState*pstate,ColumnRef*cref,Node*var);
@@ -451,11 +452,11 @@ do_compile(FunctionCallInfo fcinfo,
451452
out_arg_variables[num_out_args++]=argvariable;
452453

453454
/* Add to namespace under the $n name */
454-
plpgsql_ns_additem(argitemtype,argvariable->dno,buf);
455+
add_parameter_name(argitemtype,argvariable->dno,buf);
455456

456457
/* If there's a name for the argument, make an alias */
457458
if (argnames&&argnames[i][0]!='\0')
458-
plpgsql_ns_additem(argitemtype,argvariable->dno,
459+
add_parameter_name(argitemtype,argvariable->dno,
459460
argnames[i]);
460461
}
461462

@@ -913,6 +914,31 @@ plpgsql_compile_error_callback(void *arg)
913914
}
914915

915916

917+
/*
918+
* Add a name for a function parameter to the function's namespace
919+
*/
920+
staticvoid
921+
add_parameter_name(intitemtype,intitemno,constchar*name)
922+
{
923+
/*
924+
* Before adding the name, check for duplicates. We need this even though
925+
* functioncmds.c has a similar check, because that code explicitly
926+
* doesn't complain about conflicting IN and OUT parameter names. In
927+
* plpgsql, such names are in the same namespace, so there is no way to
928+
* disambiguate.
929+
*/
930+
if (plpgsql_ns_lookup(plpgsql_ns_top(), true,
931+
name,NULL,NULL,
932+
NULL)!=NULL)
933+
ereport(ERROR,
934+
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
935+
errmsg("parameter name \"%s\" used more than once",
936+
name)));
937+
938+
/* OK, add the name */
939+
plpgsql_ns_additem(itemtype,itemno,name);
940+
}
941+
916942
/*
917943
* Add a dummy RETURN statement to the given function's body
918944
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp