{"record":{"id":"9da85ab713d9e362","repo":"prestodb/presto","slug":"ambiguous-function-call-9da85a","errorCode":"AMBIGUOUS_FUNCTION_CALL","errorMessage":"AMBIGUOUS_FUNCTION_CALL semantic error with cause message","messagePattern":"AMBIGUOUS_FUNCTION_CALL semantic error with cause message","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java","lineNumber":1970,"sourceCode":"            Optional<Map<SqlFunctionId, SqlInvokedFunction>> sessionFunctions,\n            Optional<TransactionId> transactionId,\n            FunctionCall node,\n            List<TypeSignatureProvider> argumentTypes,\n            FunctionAndTypeResolver functionAndTypeResolver)\n    {\n        try {\n            return functionAndTypeResolver.resolveFunction(\n                    sessionFunctions,\n                    transactionId,\n                    functionAndTypeResolver.qualifyObjectName(node.getName()),\n                    argumentTypes);\n        }\n        catch (PrestoException e) {\n            if (e.getErrorCode().getCode() == StandardErrorCode.FUNCTION_NOT_FOUND.toErrorCode().getCode()) {\n                throw new SemanticException(SemanticErrorCode.FUNCTION_NOT_FOUND, node, e.getMessage());\n            }\n            if (e.getErrorCode().getCode() == StandardErrorCode.AMBIGUOUS_FUNCTION_CALL.toErrorCode().getCode()) {\n                throw new SemanticException(SemanticErrorCode.AMBIGUOUS_FUNCTION_CALL, node, e.getMessage());\n            }\n            throw e;\n        }\n    }\n\n    public static Map<NodeRef<Expression>, Type> getExpressionTypes(\n            Session session,\n            Metadata metadata,\n            SqlParser sqlParser,\n            TypeProvider types,\n            Expression expression,\n            Map<NodeRef<Parameter>, Expression> parameters,\n            WarningCollector warningCollector)\n    {\n        return getExpressionTypes(session, metadata, sqlParser, types, expression, parameters, warningCollector, false);\n    }\n\n    public static Map<NodeRef<Expression>, Type> getExpressionTypes(","sourceCodeStart":1952,"sourceCodeEnd":1988,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/ExpressionAnalyzer.java#L1952-L1988","documentation":"When function resolution is ambiguous — the argument types match more than one registered function signature — the registry's AMBIGUOUS_FUNCTION_CALL PrestoException is converted into a SemanticException AMBIGUOUS_FUNCTION_CALL tied to the FunctionCall node, preserving the cause message.","triggerScenarios":"Invoking an overloaded function with argument types (often NULLs or exact types matching multiple overloads) that do not uniquely select a signature during analysis.","commonSituations":"Passing NULL or untyped literals to overloaded functions (e.g. greatest(NULL, NULL)), calls that exactly match both a builtin and a catalog-registered function.","solutions":["CAST the ambiguous arguments so exactly one overload matches (e.g. CAST(NULL AS DOUBLE))","Qualify the function name with its catalog/schema if a same-named function shadows the builtin","Remove or rename a user-defined function creating the ambiguous overload"],"exampleFix":"// before\nSELECT greatest(NULL, NULL)\n// after\nSELECT greatest(CAST(NULL AS BIGINT), CAST(NULL AS BIGINT))","handlingStrategy":"try-catch","validationCode":"// Check how many overloads match the intended signature\nSELECT function_name, argument_types FROM system.metadata.functions\nWHERE function_name = 'greatest'; -- >1 match on identical types = risk of ambiguity","typeGuard":null,"tryCatchPattern":"try {\n    return session.execute(sql);\n} catch (SemanticException e) {\n    if (e.getCode() == SemanticErrorCode.AMBIGUOUS_FUNCTION_CALL) {\n        throw new IllegalArgumentException(\"Ambiguous call — add explicit CASTs to select one overload: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["CAST NULL and untyped literal arguments to concrete types","Qualify function names to avoid builtin/UDF shadowing","Avoid registering exact-duplicate signatures"],"tags":["ambiguous-function-call","overload-resolution","presto"],"backgroundTag":"ambiguous-function-call","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}