{"record":{"id":"e9ba6998a877aa57","repo":"prestodb/presto","slug":"invalid-function-argument-e9ba69","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Escape string must be a single character","messagePattern":"Escape string must be a single character","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/LikeFunctions.java","lineNumber":234,"sourceCode":"        byte[] bytes = regex.toString().getBytes(UTF_8);\n        // Option.MULTILINE specifies that wildcard characters (. and *) should match newlines\n        // Option.SINGLELINE specifies that anchors (^ and $) should match the beginning and end of\n        // input rather than the beginning and end of the line\n        return new Regex(bytes, 0, bytes.length, Option.MULTILINE | Option.SINGLELINE, NonStrictUTF8Encoding.INSTANCE, SYNTAX);\n    }\n\n    @SuppressWarnings(\"NumericCastThatLosesPrecision\")\n    private static char getEscapeChar(Slice escape)\n    {\n        String escapeString = escape.toStringUtf8();\n        if (escapeString.isEmpty()) {\n            // escaping disabled\n            return (char) -1; // invalid character\n        }\n        if (escapeString.length() == 1) {\n            return escapeString.charAt(0);\n        }\n        throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Escape string must be a single character\");\n    }\n}\n","sourceCodeStart":216,"sourceCodeEnd":237,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/LikeFunctions.java#L216-L237","documentation":"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.","triggerScenarios":"Calling like(value, pattern, escape) or like_pattern(...) where the third argument is a multi-character string, e.g. like('a', 'a%', '!!').","commonSituations":"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.","solutions":["Pass exactly one character as the escape argument","Use the empty string '' to disable escaping instead of a multi-char value","Escape at most one special character and remove extra escape characters from the literal"],"exampleFix":"// before\nSELECT like('50%', '50\\%%', '\\\\!'); -- escape string is two chars\n// after\nSELECT like('50%', '50!%', '!'); -- single-char escape, '%' escaped","handlingStrategy":"validation","validationCode":"// Validate escape argument before calling like(value, pattern, escape)\nboolean isValidEscape(String escape) {\n    return escape == null || escape.length() <= 1; // null/'' disables escaping; 1 char is valid\n}","typeGuard":null,"tryCatchPattern":"// SQL: wrap in try-catch equivalent\nSELECT try(\n  like(col, pattern, escape)\n); -- or catch PrestoException INVALID_FUNCTION_ARGUMENT in Java callers","preventionTips":["Always pass a single-character escape (or '' to disable escaping)","Beware doubled backslashes in SQL literals turning one char into two","Remember SQL LIKE escape semantics differ from regex escapes"],"tags":["presto","like-pattern","escape-char","invalid-function-argument"],"backgroundTag":"invalid-escape-character","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"}