Skip to content

Use precedence-aware parentheses for regex operands - #3927

Merged
roji merged 1 commit into
mainfrom
roji-sql-operator-parentheses
Oct 4, 2026
Merged

roji merged 1 commit into
mainfrom
roji-sql-operator-parentheses

Conversation

@roji

@roji roji commented Oct 4, 2026

Copy link
Copy Markdown
Member

Fixes #3923.

Use RequiresParentheses for 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.

  • Correct regex and concatenation precedence to PostgreSQL's generic-operator category.
  • Make JSON traversal participate in parentheses decisions while preserving existing CAST handling.
  • Add regression coverage for JSON DOM and ToJson operands, nested JSON paths, concatenation, and regex options.
  • Update the six JSON-existence SQL baselines affected by shared traversal grouping.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 4, 2026 09:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
roji enabled auto-merge (squash) October 4, 2026 09:36
@roji
roji merged commit b123371 into main Oct 4, 2026
16 checks passed
@roji
roji deleted the roji-sql-operator-parentheses branch October 4, 2026 09:37
roji added a commit that referenced this pull request Oct 4, 2026
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.

Missing Parantheses around JSON patterns in generated SQL

2 participants