prestodb/presto · error · PrestoException
INVALID_FUNCTION_ARGUMENT
INVALID_FUNCTION_ARGUMENT
Error message
No value '%d' in enum type %s
What it means
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.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/type/LongEnumOperators.java:162
}
@ScalarOperator(BETWEEN)
@TypeParameter(value = "T", boundedBy = BIGINT_ENUM)
@SqlType(StandardTypes.BOOLEAN)
public static boolean between(@SqlType("T") long value, @SqlType("T") long min, @SqlType("T") long max)
{
return min <= value && value <= max;
}
@Description("Get the key corresponding to an enum value")
@ScalarFunction("enum_key")
@TypeParameter(value = "T", boundedBy = BIGINT_ENUM)
@SqlType(StandardTypes.VARCHAR)
public static Slice enumKey(@TypeParameter("T") BigintEnumType enumType, @SqlType("T") long value)
{
Optional<String> key = enumType.getEnumKeyForValue(value);
if (!key.isPresent()) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("No value '%d' in enum type %s", value, enumType.getTypeSignature().getBase()));
}
return utf8Slice(key.get());
}
}
View on GitHub (pinned to 55bb57d202)
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.
Example fix
// before SELECT enum_key(country_code, 999); // after SELECT CASE WHEN v IN (1,2,3) THEN enum_key(country_code, v) ELSE NULL END FROM t;
Defensive patterns
Strategy: validation
Validate before calling
-- SQL-side pre-check before calling enum_key
SELECT CASE WHEN v IN (SELECT value FROM enum_values('myschema.myenum'))
THEN enum_key(myenum_col, v) ELSE NULL END; Type guard
boolean isValidEnumValue(long v, BigintEnumType enumType) {
return enumType.getEnumKeyForValue(v).isPresent();
} Try / catch
try {
return enumKey(enumType, value);
} catch (PrestoException e) {
if (INVALID_FUNCTION_ARGUMENT.equals(e.getErrorCode()) && e.getMessage().startsWith("No value")) {
return fallbackKeyFor(value); // or return null
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- INVALID_FUNCTION_ARGUMENT
- INVALID_FUNCTION_ARGUMENT
- Enum definition expected, got %s
- Unexpected varchar value in numeric enum signature
- Cannot parse enum signature
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/2001dbdad30c8632.
Report an issue: GitHub.