Repository navigation
feat: the ESCAPE clause of the pattern operators - #27
Merged
Merged
Conversation
PostgreSQL writes "string LIKE pattern [ESCAPE escape-character]", and the same after SIMILAR TO; the clause was not part of this grammar, and "name LIKE 'x!%' ESCAPE '!'" was refused. It follows LIKE, ILIKE, their negations and SIMILAR TO, written with the keyword, in any case. The escape character is a string of one character, or empty to turn escaping off. What PostgreSQL 18.6 refuses is refused: two characters (invalid escape string), a number, a boolean or a column as the escape, and the clause after the ~~ operators, which take none. BinaryOperatorNode and SimilarToNode carry it as Escape, nil without a clause, which is every filter v1.0.5 accepted; String() writes it. A new field and nothing else changed: a minor version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
PostgreSQL writes
string LIKE pattern [ESCAPE escape-character], and the same afterSIMILAR TO. The clause was not part of this grammar, soname LIKE 'x!%' ESCAPE '!'was refused: a pattern could escape only with the backslash.What changes
LIKE,ILIKE, their negations andSIMILAR TO, written with the keyword, in any case.'é'is one). An empty string turns escaping off.invalid escape string);~~,~~*,!~~and!~~*, which take none.BinaryOperatorNodeandSimilarToNodecarry it asEscape. It is nil without a clause, which is every filter v1.0.5 accepted, andString()writes it.How it was checked
TestFilterParser_TheEscapeClausewas run against PostgreSQL 18.6 asSELECT … WHERE (<input>), the version and table shape the existing pattern tests use. What it answered is in each row's comment:ESCAPE ''andESCAPE 'é', plus one in an expression;~~operators taking the clause.SIMILAR TO.String().NOT LIKEkeyword treated as the!~~operator.go test -racepasses, coverage is 97.6%, andgolangci-lintreports 0 issues.Docs:
filtering.md(the patterns section, the AST class diagram and table),migration.md(a v1.0.5 → v1.1.0 section).After this merges and
v1.1.0is tagged, the service and the template each take the bump in a PR of their own.🤖 Generated with Claude Code