prestodb/presto · error · ParsingException
Spaces are not allowed between 'X' and the starting quote of
Error message
Spaces are not allowed between 'X' and the starting quote of a binary literal
What it means
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.
Source
Thrown at presto-parser/src/main/java/com/facebook/presto/sql/tree/GenericLiteral.java:48
{
this(Optional.empty(), type, value);
}
public GenericLiteral(NodeLocation location, String type, String value)
{
this(Optional.of(location), type, value);
}
private GenericLiteral(Optional<NodeLocation> location, String type, String value)
{
super(location);
requireNonNull(type, "type is null");
requireNonNull(value, "value is null");
if (type.equalsIgnoreCase("X")) {
// we explicitly disallow "X" as type name, so if the user arrived here,
// it must be because that he intended to give a binaryLiteral instead, but
// added whitespace between the X and quote
throw new ParsingException("Spaces are not allowed between 'X' and the starting quote of a binary literal", location.get());
}
this.type = type;
this.value = value;
}
public String getType()
{
return type;
}
public String getValue()
{
return value;
}
@Override
public <R, C> R accept(AstVisitor<R, C> visitor, C context)
{View on GitHub (pinned to 55bb57d202)
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
Example fix
// before String sql = "SELECT X 'ABCD'"; // after String sql = "SELECT X'ABCD'";
Defensive patterns
Strategy: validation
Validate before calling
// Normalize 'X \'hex\'' to 'X\'hex\'' before parsing
String normalized = sql.replaceAll("(?i)\\bX\\s+'", "X'"); Type guard
boolean hasSpaceAfterBinaryPrefix(String sql) {
return sql != null && java.util.regex.Pattern.compile("(?i)\\bX\\s+'").matcher(sql).find();
} Try / catch
try {
return sqlParser.createStatement(sql);
} catch (ParsingException e) {
if (e.getMessage() != null && e.getMessage().contains("Spaces are not allowed between 'X'")) {
return sqlParser.createStatement(sql.replaceAll("(?i)\\bX\\s+'", "X'"));
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Binary literal can only contain hexadecimal digits
- Binary literal must contain an even number of digits
- NOT_SUPPORTED
- INVALID_LITERAL
- INVALID_TABLE_PROPERTY
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/68e667e12d69b48f.
Report an issue: GitHub.