apache/shardingsphere · error · SQLParsingException

42000

42000

Error message

You have an error in your SQL syntax: %s

What it means

Thrown by SQLParserErrorListener.syntaxError, the singleton ANTLR error listener registered during the LL (full) parse phase in SQLParserExecutor.twoPhaseParse. When ANTLR reports any syntax error in LL mode, the listener converts it directly into SQLParsingException carrying the offending symbol and line, so the failure surfaces with precise position info (message, offendingSymbol, line) rather than the raw SQL text.

Source

Thrown at parser/sql/engine/core/src/main/java/org/apache/shardingsphere/sql/parser/engine/core/database/parser/SQLParserErrorListener.java:47

 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SQLParserErrorListener extends BaseErrorListener {
    
    private static final SQLParserErrorListener INSTANCE = new SQLParserErrorListener();
    
    /**
     * Get instance.
     *
     * @return instance
     */
    public static SQLParserErrorListener getInstance() {
        return INSTANCE;
    }
    
    @Override
    public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line, final int charPositionInLine,
                            final String message, final RecognitionException e) {
        throw new SQLParsingException(message, offendingSymbol, line);
    }
}

View on GitHub (pinned to e952770a21)

Solutions

  1. Use the exception's offending symbol and line fields to locate the exact broken token
  2. Run the same SQL directly against the target database to confirm whether the database or only ShardingSphere's grammar rejects it
  3. If the database accepts it, check for a fixed grammar in a newer ShardingSphere release and upgrade
  4. Simplify the SQL (remove hints/comments/special clauses) to isolate the unsupported construct
  5. Report the statement to the ShardingSphere issue tracker if the dialect genuinely supports it

Example fix

// before
String sql = "SELECT * FORM t"; // FORM typo
sqlParserExecutor.parse(sql); // SQLParsingException, offendingSymbol=FORM, line=1

// after
String sql = "SELECT * FROM t";
sqlParserExecutor.parse(sql);
Defensive patterns

Strategy: try-catch

Try / catch

try {
    ParseASTNode ast = executor.parse(sql);
} catch (SQLParsingException e) {
    // e carries offendingSymbol + line: log them for precise user feedback
    log.warn("Syntax error near line {}: {}", e.getLine(), e.getOffendingToken());
}

Prevention

When it happens

Trigger: A statement that fails fast SLL parsing (ParseCancellationException) and then, after reset to PredictionMode.LL with the default listeners removed and this listener added, still contains a syntax error — ANTLR calls syntaxError and the exception is thrown immediately. Typical for truly malformed SQL in any supported dialect.

Common situations: User-submitted SQL with typos; ORM-generated SQL that uses syntax the dialect grammar does not yet support; SQL from a newer database version than the grammar files; escaped/unescaped quote mismatches; SQL containing database-specific hints the grammar rejects.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/e045a6b9a7980113. Report an issue: GitHub.