{"record":{"id":"0d705ba3304370e0","repo":"prestodb/presto","slug":"invalid-function-argument-0d705b","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"0 is an invalid instance position for array_position.","messagePattern":"0 is an invalid instance position for array_position\\.","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/ArrayPositionWithIndexFunction.java","lineNumber":53,"sourceCode":"@ScalarFunction(\"array_position\")\npublic class ArrayPositionWithIndexFunction\n{\n    protected ArrayPositionWithIndexFunction() {}\n\n    @TypeParameter(\"T\")\n    @SqlType(StandardTypes.BIGINT)\n    public static long arrayPositionWithIndex(\n            @TypeParameter(\"T\") Type type,\n            @OperatorDependency(operator = EQUAL, argumentTypes = {\"T\", \"T\"}) MethodHandle equalMethodHandle,\n            @SqlType(\"array(T)\") Block array,\n            @SqlType(\"T\") boolean element,\n            @SqlType(StandardTypes.BIGINT) long instance)\n    {\n        int size = array.getPositionCount();\n        int instancesFound = 0;\n\n        if (instance == 0) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"0 is an invalid instance position for array_position.\");\n        }\n\n        int startIndex = instance > 0 ? 0 : size - 1;\n        int stopIndex = instance > 0 ? size : -1;\n        int stepSize = instance > 0 ? 1 : -1;\n        instance = Math.abs(instance);\n\n        for (int i = startIndex; i != stopIndex; i += stepSize) {\n            if (!array.isNull(i)) {\n                try {\n                    boolean arrayValue = type.getBoolean(array, i);\n                    Boolean result = (Boolean) equalMethodHandle.invoke(arrayValue, element);\n                    checkNotIndeterminate(result);\n                    if (result) {\n                        instancesFound++;\n                        if (instancesFound == instance) {\n                            return i + 1; // result is 1-based (instead of 0)\n                        }","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/ArrayPositionWithIndexFunction.java#L35-L71","documentation":"Input validation in the three-argument array_position function: the instance parameter tells Presto which matching occurrence to return and is 1-based, so passing 0 is rejected before scanning the array. It fires on array_position(array, element, 0) regardless of the array contents.","triggerScenarios":"Thrown at presto-main-base/src/main/java/com/facebook/presto/operator/scalar/ArrayPositionWithIndexFunction.java:53 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an instance value of 1 or greater (or negative to count from the end where supported)","Drop the instance argument entirely to find the first occurrence","Fix generated SQL that binds 0 as the instance parameter"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}