Skip to content

Keep doubled quote escapes within one generalized SQL literal - #705

Merged
macbre merged 1 commit into
macbre:masterfrom
dailyun:fix/generalize-escaped-strings
Oct 20, 2026
Merged

macbre merged 1 commit into
macbre:masterfrom
dailyun:fix/generalize-escaped-strings

Conversation

@dailyun

@dailyun dailyun commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Parser("SELECT 'O''Reilly'").generalize currently returns SELECT XX, while an ordinary string returns SELECT X. One SQL literal is split at its doubled quote escapes, so equivalent query shapes can end up in different groups. LIKE has the same problem.

Use the existing sqlglot tokenizer to replace complete string tokens before collapsing LIKE clauses. Preserve N/n prefixes and the previous best-effort fallback when tokenization fails. Queries without single quotes skip the added tokenizer pass; queries with literals incur that extra pass.

Added 14 cases covering doubled quotes in SELECT, national strings and LIKE, separate literals, and unterminated input. Against the original implementation, 13 fail and the malformed-input control passes. After the change, the full suite passes: 290 tests, 100% coverage. Mypy, Ruff, formatting and diff checks pass on Python 3.13/macOS arm64. No dependencies changed.

Prepared and tested with OpenAI Codex; not human-reviewed before submission.

@macbre
macbre enabled auto-merge (squash) October 20, 2026 16:10
@macbre
macbre merged commit 5ee5500 into macbre:master Oct 20, 2026
11 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.

2 participants