Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the handling of PostgreSQL "IS NOT DISTINCT FROM" expressions in trigger conditions by adding proper parsing and normalization support.
- Adds parsing support for both "IS DISTINCT FROM" and "IS NOT DISTINCT FROM" expressions in the parser
- Implements condition normalization to handle PostgreSQL's internal representation of "NOT (x IS DISTINCT FROM y)" as "x IS NOT DISTINCT FROM y"
- Adds comprehensive test data covering both distinct operators in trigger WHEN clauses
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ir/parser.go | Adds parsing logic for AEXPR_DISTINCT and AEXPR_NOT_DISTINCT expression types |
| ir/inspector.go | Implements normalization of trigger conditions and regex-based pattern conversion for NOT DISTINCT FROM |
| testdata/diff/create_trigger/add_trigger_when_distinct/* | Test cases demonstrating proper handling of both IS DISTINCT FROM and IS NOT DISTINCT FROM in triggers |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // (.+?) - non-greedy capture of left expression | ||
| // \s+IS\s+DISTINCT\s+FROM\s+ - " IS DISTINCT FROM " with flexible whitespace | ||
| // (.+)$ - capture the right expression to end of string | ||
| re := regexp.MustCompile(`^NOT\s+(.+?)\s+IS\s+DISTINCT\s+FROM\s+(.+)$`) |
There was a problem hiding this comment.
The regex is compiled on every function call. Consider moving the compilation to package level or use a sync.Once to compile it once for better performance.
|
|
||
| // Use pg_query to normalize the expression for consistent formatting | ||
| // This handles complex expressions, case normalization, etc. | ||
| normalizedCondition := normalizeExpressionWithPgQuery(condition) |
There was a problem hiding this comment.
The function normalizeExpressionWithPgQuery is called but not defined in this file or imported. This will cause a compilation error.
Fix #38