{"record":{"id":"2001dbdad30c8632","repo":"prestodb/presto","slug":"invalid-function-argument-2001db","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"No value '%d' in enum type %s","messagePattern":"No value '(.+?)' in enum type (.+?)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/LongEnumOperators.java","lineNumber":162,"sourceCode":"    }\n\n    @ScalarOperator(BETWEEN)\n    @TypeParameter(value = \"T\", boundedBy = BIGINT_ENUM)\n    @SqlType(StandardTypes.BOOLEAN)\n    public static boolean between(@SqlType(\"T\") long value, @SqlType(\"T\") long min, @SqlType(\"T\") long max)\n    {\n        return min <= value && value <= max;\n    }\n\n    @Description(\"Get the key corresponding to an enum value\")\n    @ScalarFunction(\"enum_key\")\n    @TypeParameter(value = \"T\", boundedBy = BIGINT_ENUM)\n    @SqlType(StandardTypes.VARCHAR)\n    public static Slice enumKey(@TypeParameter(\"T\") BigintEnumType enumType, @SqlType(\"T\") long value)\n    {\n        Optional<String> key = enumType.getEnumKeyForValue(value);\n        if (!key.isPresent()) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format(\"No value '%d' in enum type %s\", value, enumType.getTypeSignature().getBase()));\n        }\n        return utf8Slice(key.get());\n    }\n}\n","sourceCodeStart":144,"sourceCodeEnd":167,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/LongEnumOperators.java#L144-L167","documentation":"enumKey is the SQL function that maps a BIGINT enum value back to its key name for types annotated @BigIntegerEnum (BIGINT_ENUM). When the supplied long does not correspond to any registered enum constant value, the lookup returns an empty Optional and the function throws INVALID_FUNCTION_ARGUMENT. This is a user-supplied-data validation error, not an engine bug.","triggerScenarios":"Calling the enum_key(T, value) scalar function (or any generated operator using enumKey) with a BIGINT that is not one of the enum type's declared constant values, e.g. enum_key(MyEnum, 999) when 999 is not defined.","commonSituations":"User queries passing hard-coded numeric codes that were removed or renumbered in an updated enum definition; data imported from another system with codes absent from the Presto enum type; typos in numeric literals.","solutions":["Validate the value against the enum's defined values before calling enum_key (e.g., via a CASE or a lookup table).","If the value is legitimately missing, add it to the enum type definition and redeploy, or map it to a defined constant.","Update stale client code after enum renumbering so it uses the current constant values."],"exampleFix":"// before\nSELECT enum_key(country_code, 999);\n// after\nSELECT CASE WHEN v IN (1,2,3) THEN enum_key(country_code, v) ELSE NULL END FROM t;","handlingStrategy":"validation","validationCode":"-- SQL-side pre-check before calling enum_key\nSELECT CASE WHEN v IN (SELECT value FROM enum_values('myschema.myenum'))\n       THEN enum_key(myenum_col, v) ELSE NULL END;","typeGuard":"boolean isValidEnumValue(long v, BigintEnumType enumType) {\n    return enumType.getEnumKeyForValue(v).isPresent();\n}","tryCatchPattern":"try {\n    return enumKey(enumType, value);\n} catch (PrestoException e) {\n    if (INVALID_FUNCTION_ARGUMENT.equals(e.getErrorCode()) && e.getMessage().startsWith(\"No value\")) {\n        return fallbackKeyFor(value); // or return null\n    }\n    throw e;\n}","preventionTips":["Keep an application-side map of valid enum codes and validate before querying.","Re-validate hard-coded codes after every enum definition change or renumbering.","Prefer joining against a reference/lookup table over hard-coded numeric literals in SQL."],"tags":["presto","enum","invalid-argument","sql-function"],"backgroundTag":"invalid-enum-value","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"}