prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Escape string must be a single character

What it means

likePattern(varchar, varchar escape) builds a LIKE pattern where the escape string must be exactly one character (returned as a char used to escape wildcards). getEscapeChar throws INVALID_FUNCTION_ARGUMENT when the supplied escape string has length != 1 (and length 0 disables escaping). Empty string is valid (escaping disabled); 2+ characters is not.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/type/LikeFunctions.java:234

        byte[] bytes = regex.toString().getBytes(UTF_8);
        // Option.MULTILINE specifies that wildcard characters (. and *) should match newlines
        // Option.SINGLELINE specifies that anchors (^ and $) should match the beginning and end of
        // input rather than the beginning and end of the line
        return new Regex(bytes, 0, bytes.length, Option.MULTILINE | Option.SINGLELINE, NonStrictUTF8Encoding.INSTANCE, SYNTAX);
    }

    @SuppressWarnings("NumericCastThatLosesPrecision")
    private static char getEscapeChar(Slice escape)
    {
        String escapeString = escape.toStringUtf8();
        if (escapeString.isEmpty()) {
            // escaping disabled
            return (char) -1; // invalid character
        }
        if (escapeString.length() == 1) {
            return escapeString.charAt(0);
        }
        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Escape string must be a single character");
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Pass exactly one character as the escape argument
  2. Use the empty string '' to disable escaping instead of a multi-char value
  3. Escape at most one special character and remove extra escape characters from the literal

Example fix

// before
SELECT like('50%', '50\%%', '\\!'); -- escape string is two chars
// after
SELECT like('50%', '50!%', '!'); -- single-char escape, '%' escaped
Defensive patterns

Strategy: validation

Validate before calling

// Validate escape argument before calling like(value, pattern, escape)
boolean isValidEscape(String escape) {
    return escape == null || escape.length() <= 1; // null/'' disables escaping; 1 char is valid
}

Try / catch

// SQL: wrap in try-catch equivalent
SELECT try(
  like(col, pattern, escape)
); -- or catch PrestoException INVALID_FUNCTION_ARGUMENT in Java callers

Prevention

When it happens

Trigger: Calling like(value, pattern, escape) or like_pattern(...) where the third argument is a multi-character string, e.g. like('a', 'a%', '!!').

Common situations: Users confusing SQL LIKE escape syntax (single char) with regex-style multi-char escapes; copying escape sequences like '\\!' from other engines; string literals where an intended single char became two due to doubled backslashes.

Related errors


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