prestodb/presto · error · PrestoException

INVALID_CAST_ARGUMENT

INVALID_CAST_ARGUMENT

Error message

No value '%s' in enum '%s'

What it means

Cast error from varchar-to-enum casting: the string being cast is not one of the values declared for the target ENUM type. The %s pair names the offending value and the enum type; the faulty input is the string being cast.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/type/EnumCasts.java:45

import static com.facebook.presto.common.function.OperatorType.CAST;
import static com.facebook.presto.common.type.StandardTypes.BIGINT;
import static com.facebook.presto.common.type.StandardTypes.BIGINT_ENUM;
import static com.facebook.presto.common.type.StandardTypes.VARCHAR_ENUM;
import static com.facebook.presto.spi.StandardErrorCode.INVALID_CAST_ARGUMENT;

public final class EnumCasts
{
    private EnumCasts()
    {
    }

    @ScalarOperator(CAST)
    @TypeParameter(value = "T", boundedBy = VARCHAR_ENUM)
    @SqlType("T")
    public static Slice castVarcharToEnum(@TypeParameter("T") Type enumType, @SqlType(StandardTypes.VARCHAR) Slice value)
    {
        if (!(((VarcharEnumType) enumType).getEnumMap().values().contains(value.toStringUtf8()))) {
            throw new PrestoException(INVALID_CAST_ARGUMENT,
                    String.format(
                            "No value '%s' in enum '%s'",
                            value.toStringUtf8(),
                            enumType.getTypeSignature().getBase()));
        }
        return value;
    }

    @ScalarOperator(CAST)
    @TypeParameter(value = "T", boundedBy = VARCHAR_ENUM)
    @SqlType(StandardTypes.VARCHAR)
    public static Slice castEnumToVarchar(@SqlType("T") Slice value)
    {
        return value;
    }

    @ScalarOperator(CAST)
    @TypeParameter(value = "T", boundedBy = BIGINT_ENUM)

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Add the missing value to the enum definition
  2. Normalize the input (trim/lowercase) to match enum spelling exactly
  3. Inspect the enum's allowed values and fix the data or the mapping

Example fix

// before (SQL)
SELECT CAST(status AS order_status) FROM t -- status = 'cancelled '
// after
SELECT CAST(trim(lower(status)) AS order_status) FROM t
Defensive patterns

Strategy: validation

Validate before calling

-- check values against the enum before casting
SELECT DISTINCT status FROM t; -- compare against enum's declared values; normalize with trim/lower if needed

Try / catch

SELECT try(CAST(status AS order_status)) FROM t -- NULL for unknown labels

Prevention

When it happens

Trigger: CAST(varchar_value AS <enum type>) where the string is not in the enum's defined value set (castVarcharToEnum in EnumCasts.java).

Common situations: Source data containing new/renamed labels not yet added to the enum, whitespace or case mismatches ('Active' vs 'active'), stale enum definitions after upstream schema changes.

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


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