{"record":{"id":"68e667e12d69b48f","repo":"prestodb/presto","slug":"spaces-are-not-allowed-between-x-and-the-startin","errorCode":null,"errorMessage":"Spaces are not allowed between 'X' and the starting quote of a binary literal","messagePattern":"Spaces are not allowed between 'X' and the starting quote of a binary literal","errorType":"exception","errorClass":"ParsingException","httpStatus":null,"severity":"error","filePath":"presto-parser/src/main/java/com/facebook/presto/sql/tree/GenericLiteral.java","lineNumber":48,"sourceCode":"    {\n        this(Optional.empty(), type, value);\n    }\n\n    public GenericLiteral(NodeLocation location, String type, String value)\n    {\n        this(Optional.of(location), type, value);\n    }\n\n    private GenericLiteral(Optional<NodeLocation> location, String type, String value)\n    {\n        super(location);\n        requireNonNull(type, \"type is null\");\n        requireNonNull(value, \"value is null\");\n        if (type.equalsIgnoreCase(\"X\")) {\n            // we explicitly disallow \"X\" as type name, so if the user arrived here,\n            // it must be because that he intended to give a binaryLiteral instead, but\n            // added whitespace between the X and quote\n            throw new ParsingException(\"Spaces are not allowed between 'X' and the starting quote of a binary literal\", location.get());\n        }\n        this.type = type;\n        this.value = value;\n    }\n\n    public String getType()\n    {\n        return type;\n    }\n\n    public String getValue()\n    {\n        return value;\n    }\n\n    @Override\n    public <R, C> R accept(AstVisitor<R, C> visitor, C context)\n    {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-parser/src/main/java/com/facebook/presto/sql/tree/GenericLiteral.java#L30-L66","documentation":"GenericLiteral handles typed literals like DATE '...' or BIGINT '...'. The type name 'X' is reserved for binary literals (X'hex'), and whitespace between the X and the quote makes the lexer see a GenericLiteral with type \"X\" instead of a binary literal, which the constructor explicitly rejects.","triggerScenarios":"Parsing SQL like X 'ABCD' (space between X and the quoted string) — the token parses as a generic literal of type 'X', throwing this error.","commonSituations":"Hand-formatted SQL with a space after the X, code formatters that insert a space between the type and the quote, copy-pasted queries reformatted by an IDE.","solutions":["Remove the space: write X'ABCD' with no gap between X and the quote","Disable auto-formatting that inserts a space before string literals in this context","Escape/normalize the literal in generated SQL"],"exampleFix":"// before\nString sql = \"SELECT X 'ABCD'\";\n// after\nString sql = \"SELECT X'ABCD'\";","handlingStrategy":"validation","validationCode":"// Normalize 'X \\'hex\\'' to 'X\\'hex\\'' before parsing\nString normalized = sql.replaceAll(\"(?i)\\\\bX\\\\s+'\", \"X'\");","typeGuard":"boolean hasSpaceAfterBinaryPrefix(String sql) {\n    return sql != null && java.util.regex.Pattern.compile(\"(?i)\\\\bX\\\\s+'\").matcher(sql).find();\n}","tryCatchPattern":"try {\n    return sqlParser.createStatement(sql);\n} catch (ParsingException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Spaces are not allowed between 'X'\")) {\n        return sqlParser.createStatement(sql.replaceAll(\"(?i)\\\\bX\\\\s+'\", \"X'\"));\n    }\n    throw e;\n}","preventionTips":["Write X'..' with no space between X and the quote","Configure IDE formatters not to insert spaces before literals","Add a regex check for X-space-quote in SQL review tooling","Normalize literals centrally when generating SQL"],"tags":["sql","literal","binary","whitespace"],"backgroundTag":"invalid-literal-value","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"}