Skip to content

Comments

fix: trigger when IS NOT DISTINCT FROM#42

Merged
tianzhou merged 1 commit intomainfrom
distinct-from
Sep 25, 2025
Merged

fix: trigger when IS NOT DISTINCT FROM#42
tianzhou merged 1 commit intomainfrom
distinct-from

Conversation

@tianzhou
Copy link
Contributor

Fix #38

Copilot AI review requested due to automatic review settings September 25, 2025 05:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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+(.+)$`)
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

// Use pg_query to normalize the expression for consistent formatting
// This handles complex expressions, case normalization, etc.
normalizedCondition := normalizeExpressionWithPgQuery(condition)
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

The function normalizeExpressionWithPgQuery is called but not defined in this file or imported. This will cause a compilation error.

Copilot uses AI. Check for mistakes.
@tianzhou tianzhou merged commit d9727a2 into main Sep 25, 2025
2 checks passed
@tianzhou tianzhou deleted the distinct-from branch October 23, 2025 09:15
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.

Trigger WHEN clause IS DISTINCT FROM converts to equality comparison

1 participant