diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-10-08 02:39:25 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-10-08 02:39:25 +0000 |
commit | 717fa274d14d9cd25396b85bb92f567e1c623f0c (patch) | |
tree | 4fe298a9faa1fc8f038a9a1f35ee033abc3e41ed /src/backend/commands/functioncmds.c | |
parent | 2eda8dfb52ed9962920282d8384da8bb4c22514d (diff) | |
download | postgresql-717fa274d14d9cd25396b85bb92f567e1c623f0c.tar.gz postgresql-717fa274d14d9cd25396b85bb92f567e1c623f0c.zip |
Support use of function argument names to identify which actual arguments
match which function parameters. The syntax uses AS, for example
funcname(value AS arg1, anothervalue AS arg2)
Pavel Stehule
Diffstat (limited to 'src/backend/commands/functioncmds.c')
-rw-r--r-- | src/backend/commands/functioncmds.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index cf206b3f090..40097a80c72 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.111 2009/09/22 23:43:37 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.112 2009/10/08 02:39:19 tgl Exp $ * * DESCRIPTION * These routines take the parse tree and pick out the @@ -285,6 +285,39 @@ examine_parameter_list(List *parameters, Oid languageOid, if (fp->name && fp->name[0]) { + ListCell *px; + + /* + * As of Postgres 8.5 we disallow using the same name for two + * input or two output function parameters. Depending on the + * function's language, conflicting input and output names might + * be bad too, but we leave it to the PL to complain if so. + */ + foreach(px, parameters) + { + FunctionParameter *prevfp = (FunctionParameter *) lfirst(px); + + if (prevfp == fp) + break; + /* pure in doesn't conflict with pure out */ + if ((fp->mode == FUNC_PARAM_IN || + fp->mode == FUNC_PARAM_VARIADIC) && + (prevfp->mode == FUNC_PARAM_OUT || + prevfp->mode == FUNC_PARAM_TABLE)) + continue; + if ((prevfp->mode == FUNC_PARAM_IN || + prevfp->mode == FUNC_PARAM_VARIADIC) && + (fp->mode == FUNC_PARAM_OUT || + fp->mode == FUNC_PARAM_TABLE)) + continue; + if (prevfp->name && prevfp->name[0] && + strcmp(prevfp->name, fp->name) == 0) + ereport(ERROR, + (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), + errmsg("parameter name \"%s\" used more than once", + fp->name))); + } + paramNames[i] = CStringGetTextDatum(fp->name); have_names = true; } @@ -1097,6 +1130,7 @@ RenameFunction(List *name, List *argtypes, const char *newname) errmsg("function %s already exists in schema \"%s\"", funcname_signature_string(newname, procForm->pronargs, + NIL, procForm->proargtypes.values), get_namespace_name(namespaceOid)))); } |