{"record":{"id":"22c8e77267c1f63a","repo":"apache/cassandra","slug":"like-value-can-t-contain-a-other-than-at-the-sta","errorCode":null,"errorMessage":"LIKE value can't contain a % other than at the start and/or end","messagePattern":"LIKE value can't contain a % other than at the start and/or end","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/LikePattern.java","lineNumber":117,"sourceCode":"            kind = Kind.SUFFIX;\n            beginIndex += 1;\n            endIndex += 1;\n        }\n        else\n        {\n            kind = Kind.MATCHES;\n            endIndex += 1;\n        }\n\n        if (endIndex == 0 || beginIndex == endIndex)\n            throw invalidRequest(\"LIKE value can't be empty.\");\n\n        ByteBuffer newValue = value.duplicate();\n        newValue.position(beginIndex);\n        newValue.limit(endIndex);\n        // Checking if we still have WILDCARD in value and if yes return error.\n        if (ByteBufferUtil.contains(newValue, WILDCARD))\n            throw invalidRequest(\"LIKE value can't contain a % other than at the start and/or end\");\n        return new LikePattern(kind, newValue);\n    }\n}\n","sourceCodeStart":99,"sourceCodeEnd":121,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/LikePattern.java#L99-L121","documentation":"LIKE in Cassandra only supports % wildcards at the very start and/or end of the pattern (prefix, suffix, contains, or exact match). Any % appearing in the interior of the pattern after those are stripped causes this error in LikePattern.parse.","triggerScenarios":"Queries such as col LIKE 'a%b' or col LIKE '%a%b%' where a WILDCARD remains inside the trimmed ByteBuffer; ByteBufferUtil.contains(newValue, WILDCARD) detects the interior % and throws.","commonSituations":"See trigger scenarios.","solutions":["Move interior % wildcards to the start/end only, or use an exact/prefix/suffix/contains form the parser accepts","Implement in-memory filtering of the remaining matches if arbitrary wildcard search is required (e.g. LIKE prefix then filter client-side)","Use SASI/SAI index search capabilities if available for richer matching instead of LIKE"],"exampleFix":"// before\nSELECT * FROM users WHERE name LIKE 'jo%hn';\n// after\nSELECT * FROM users WHERE name LIKE '%john%'; // or use a supported prefix/suffix/contains pattern","handlingStrategy":"validation","validationCode":"function hasOnlyEdgeWildcards(p) {\n  const core = p.replace(/^%/, '').replace(/%$/, '');\n  return !core.includes('%');\n}\nif (!hasOnlyEdgeWildcards(userInput)) throw new Error('interior % not supported by Cassandra LIKE');","typeGuard":"function isCqlLikeSafe(p) { return typeof p === 'string' && !p.slice(1, -1).slice(p.startsWith('%') ? 1 : 0, p.endsWith('%') ? -1 : undefined).includes('%'); }","tryCatchPattern":null,"preventionTips":["Educate users that Cassandra LIKE supports only prefix/suffix/contains forms","Escape or reject interior % before query construction","Fall back to post-filtering in application code for complex wildcards"],"tags":["cql","like-operator","wildcard"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}