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

  1. Rename one of the duplicate parameters in the function signature.
  2. Remove the redundant parameter if it was accidentally duplicated.
  3. 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

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


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/7e4565a2c68abd6e. Report an issue: GitHub.