Skip to content

Comments

Fix Oracle dialect crash on parenthesized LIKE expression#7121

Merged
georgesittas merged 1 commit intotobymao:mainfrom
Fridayai700:fix-oracle-like-parens
Feb 22, 2026
Merged

Fix Oracle dialect crash on parenthesized LIKE expression#7121
georgesittas merged 1 commit intotobymao:mainfrom
Fridayai700:fix-oracle-like-parens

Conversation

@Fridayai700
Copy link
Contributor

Summary

Fixes #7118. SELECT * FROM t WHERE c LIKE (:var) crashes with ParseError: Required keyword: 'this' missing for <class 'sqlglot.expressions.Like'> in the Oracle dialect.

Root cause: Oracle's _parse_column_ops speculatively calls _parse_interval_span, which internally calls _parse_function(). When the current token is LIKE followed by parenthesized arguments, _parse_function consumes LIKE and tries to validate LIKE(:var) as a function call — but Like requires a this argument that isn't present, so it raises a ParseError. The existing retreat logic on line 300 never executes because the error is thrown first.

Fix: Wrap the speculative _parse_interval_span call in _try_parse, which catches ParseError and properly restores the parser state. This follows the same pattern used elsewhere in the parser for speculative parsing.

# Before (buggy):
interval_span = self._parse_interval_span(this)

# After (fixed):
interval_span = self._try_parse(lambda: self._parse_interval_span(this))

All 23 Oracle dialect tests pass (211 subtests). General parser tests also pass.

Oracle's _parse_column_ops speculatively calls _parse_interval_span,
which internally calls _parse_function.  When the current token is LIKE
followed by parenthesized arguments (e.g. LIKE (:var)), _parse_function
consumes the LIKE token and tries to validate it as a function call,
raising a ParseError because Like requires a 'this' argument.

Use _try_parse to wrap the speculative _parse_interval_span call so
that parse errors are caught and the parser state is properly restored.

Fixes tobymao#7118.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@georgesittas georgesittas merged commit 4abe929 into tobymao:main Feb 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error parsing Oracle query with LIKE and variable in parenthesis

2 participants