prestodb/presto · error · SemanticException
DUPLICATE_PARAMETER_NAME
DUPLICATE_PARAMETER_NAME
Error message
Duplicate function parameter name: %s
What it means
A CREATE FUNCTION statement declares two or more parameters with the same name. Parameter names must be unique within a function signature so calls can bind arguments unambiguously, so the analyzer raises DUPLICATE_PARAMETER_NAME listing all offending names.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java:1172
checkFunctionName(node, node.getFunctionName(), node.isTemporary());
// Check no replace with temporary functions
if (node.isTemporary() && node.isReplace()) {
throw new SemanticException(NOT_SUPPORTED, node, "REPLACE is not supported for temporary functions");
}
// Check parameter
List<String> duplicateParameters = node.getParameters().stream()
.map(SqlParameterDeclaration::getName)
.map(Identifier::getValue)
.collect(groupingBy(Function.identity(), counting()))
.entrySet()
.stream()
.filter(entry -> entry.getValue() > 1)
.map(Entry::getKey)
.collect(toImmutableList());
if (!duplicateParameters.isEmpty()) {
throw new SemanticException(DUPLICATE_PARAMETER_NAME, node, "Duplicate function parameter name: %s", Joiner.on(", ").join(duplicateParameters));
}
// Check return type
Type returnType = functionAndTypeResolver.getType(parseTypeSignature(node.getReturnType()));
List<Field> fields = node.getParameters().stream()
.map(parameter -> Field.newUnqualified(parameter.getName().getLocation(), parameter.getName().getValue(), functionAndTypeResolver.getType(parseTypeSignature(parameter.getType()))))
.collect(toImmutableList());
Scope functionScope = Scope.builder()
.withRelationType(RelationId.anonymous(), new RelationType(fields))
.build();
if (node.getBody() instanceof Return) {
Expression returnExpression = ((Return) node.getBody()).getExpression();
Type bodyType = analyzeExpression(returnExpression, functionScope).getExpressionTypes().get(NodeRef.of(returnExpression));
if (!functionAndTypeResolver.canCoerce(bodyType, returnType)) {
throw new SemanticException(TYPE_MISMATCH, node, "Function implementation type '%s' does not match declared return type '%s'", bodyType, returnType);
}
verifyNoAggregateWindowOrGroupingFunctions(analysis.getFunctionHandles(), functionAndTypeResolver, returnExpression, "CREATE FUNCTION body");View on GitHub (pinned to 55bb57d202)
Solutions
- Rename one of the duplicate parameters in the function signature.
- Remove the redundant parameter if it was accidentally duplicated.
- Fix the SQL generator/template to deduplicate parameter names.
Example fix
// before CREATE FUNCTION f(x INTEGER, x INTEGER) RETURNS INTEGER RETURN x; // after CREATE FUNCTION f(x INTEGER, y INTEGER) RETURNS INTEGER RETURN x + y;
Defensive patterns
Strategy: validation
Validate before calling
Set<String> params = parseParameterNames(createFunctionSql);
if (params.size() != parseParameterList(createFunctionSql).size()) {
throw new IllegalArgumentException("Duplicate function parameter names: " + (listSize - params.size()));
} Try / catch
try {
execute(sql);
} catch (SemanticException e) {
if (e.getCode().name().equals("DUPLICATE_PARAMETER_NAME")) {
log.error("Rename duplicated parameters reported: {}", e.getErrorMessage());
}
throw e;
} Prevention
- Define function signatures once in a shared spec and generate SQL from it.
- Add a lint rule that parses parameter lists and rejects duplicates.
- Use distinct, descriptive parameter names (e.g., start_date/end_date) instead of generic x/y reuse.
When it happens
Trigger: CREATE FUNCTION ... (x INTEGER, x VARCHAR) ... — duplicate identifiers collected from node.getParameters() produce a non-empty duplicateParameters list.
Common situations: Copy-paste of parameter declarations when extending a function's arity; renaming one parameter but forgetting the second occurrence; templated SQL generation that concatenates parameter lists with repeats.
Related errors
- FUNCTION_NOT_FOUND
- TYPE_MISMATCH
- %s is not lowercase: %s
- FUNCTION_IMPLEMENTATION_ERROR
- MUST_BE_AGGREGATE_OR_GROUP_BY
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/7e4565a2c68abd6e.
Report an issue: GitHub.