prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

No value '%s' in enum type %s

What it means

Raised by the enum_key function when the given varchar value does not correspond to any value defined in the varchar enum type T. getEnumKeyForValue returns empty and Presto throws INVALID_FUNCTION_ARGUMENT naming both the value and the enum type.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/type/VarcharEnumOperators.java:161

    }

    @ScalarOperator(BETWEEN)
    @TypeParameter(value = "T", boundedBy = VARCHAR_ENUM)
    @SqlType(StandardTypes.BOOLEAN)
    public static boolean between(@SqlType("T") Slice value, @SqlType("T") Slice min, @SqlType("T") Slice max)
    {
        return min.compareTo(value) <= 0 && value.compareTo(max) <= 0;
    }

    @Description("Get the key corresponding to an enum value")
    @ScalarFunction("enum_key")
    @TypeParameter(value = "T", boundedBy = VARCHAR_ENUM)
    @SqlType(StandardTypes.VARCHAR)
    public static Slice enumKey(@TypeParameter("T") VarcharEnumType enumType, @SqlType("T") Slice value)
    {
        Optional<String> key = enumType.getEnumKeyForValue(value.toStringUtf8());
        if (!key.isPresent()) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("No value '%s' in enum type %s", value.toStringUtf8(), enumType.getTypeSignature().getBase()));
        }
        return utf8Slice(key.get());
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Check the enum's defined values (via the type metadata/SHOW output) and use an exact, correctly cased value
  2. Update the enum type definition to include the missing value if it is legitimate
  3. Normalize the input string's case/whitespace before calling enum_key
  4. Guard with a membership check or wrap in error-handling logic in the calling code

Example fix

// before
SELECT enum_key(status_enum, status_raw) FROM t;
// after
SELECT CASE WHEN status_raw IN ('active','inactive','pending') THEN enum_key(status_enum, status_raw) ELSE NULL END FROM t;
Defensive patterns

Strategy: validation

Validate before calling

-- Presto SQL: check membership before enum_key (list values per your enum definition)
SELECT * FROM t WHERE value_col IN ('v1','v2','v3'); -- replace with actual enum values

Try / catch

-- Guard with CASE or catch at the client layer when invoking enum_key
SELECT CASE WHEN value_col IN ('v1','v2','v3') THEN enum_key(my_enum, value_col) ELSE NULL END FROM t;

Prevention

When it happens

Trigger: SELECT enum_key(MyEnumType, 'unknownValue') where the string is not a member of the enum's value set (case mismatch, stale value removed from the enum definition, or typo).

Common situations: Enum definitions evolving while data retains old values; case-sensitivity mismatches ('active' vs 'ACTIVE'); data from other systems using codes not registered in the Presto enum type.

Related errors


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