Use precedence-aware parentheses for regex operands - #3927
Merged
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The precedence changes are consistent with PostgreSQL parsing rules and are covered across the affected regex and JSON scenarios.
Review effort: Balanced
Findings: None
What changed in this PR
Updates SQL generation to preserve PostgreSQL operator precedence for regex and JSON traversal expressions.
Changes:
- Adds precedence-aware parentheses for regex operands and concatenation.
- Integrates JSON traversal into operator precedence decisions.
- Adds regression tests and updates affected SQL baselines.
| File | Description |
|---|---|
src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs |
Implements precedence-aware SQL generation. |
test/EFCore.PG.FunctionalTests/Query/NorthwindFunctionsQueryNpgsqlTest.cs |
Tests concatenated regex operands. |
test/EFCore.PG.FunctionalTests/Query/JsonQueryNpgsqlTest.cs |
Tests JSON-mapped regex operands. |
test/EFCore.PG.FunctionalTests/Query/JsonPocoQueryTest.cs |
Updates JSON-existence baselines. |
test/EFCore.PG.FunctionalTests/Query/JsonDomQueryTest.cs |
Adds comprehensive JSON regex regression coverage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
roji
enabled auto-merge (squash)
October 4, 2026 09:36
This was referenced Oct 4, 2026
This was referenced Oct 4, 2026
roji
added a commit
that referenced
this pull request
Oct 4, 2026
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.
Fixes #3923.
Use
RequiresParenthesesfor both regex operands, including the Singleline fast path and negated/case-insensitive matches. Unlike #3924, this preserves the existing SQL for constant, column, and parameter patterns instead of wrapping every pattern.ToJsonoperands, nested JSON paths, concatenation, and regex options.