Skip to content

fix: view array operator#89

Merged
tianzhou merged 1 commit intomainfrom
view_logic_expr_followup
Oct 15, 2025
Merged

fix: view array operator#89
tianzhou merged 1 commit intomainfrom
view_logic_expr_followup

Conversation

@tianzhou
Copy link
Contributor

#87 followup

Copilot AI review requested due to automatic review settings October 15, 2025 17:46
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 array operators in view definitions by ensuring that only equality operations (= ANY) are converted to IN syntax, while other operators (>, <, <>) preserve their ANY/ALL syntax.

  • Adds proper detection of equality vs. non-equality array operators
  • Implements separate formatting paths for = ANY (converted to IN) vs. other operators (preserved as ANY/ALL)
  • Adds comprehensive test coverage for various array operators in view definitions

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

File Description
ir/formatter.go Implements the core fix with enhanced ScalarArrayOpExpr formatting and operator extraction logic
testdata/diff/create_view/add_view_array_operators/. Adds test data covering various array operators to validate the fix works correctly

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

ir/formatter.go Outdated
Comment on lines 707 to 717
// Get the operator name by deparsing
deparsed, err := f.deparseNode(&pg_query.Node{Node: &pg_query.Node_ScalarArrayOpExpr{ScalarArrayOpExpr: arrayOp}})
if err != nil {
// If deparse fails, just return empty (shouldn't happen in practice)
return
}

// Check if operator is = (equality)
// Deparse will give us something like "col = ANY (...)" or "col > ANY (...)"
// We need to extract the operator
isEqualityOp := strings.Contains(deparsed, " = ANY") || strings.Contains(deparsed, "= ANY")
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

The code performs deparsing twice for the same expression - once here to check if it's an equality operator, and again in extractOperator(). Consider extracting the operator first and checking for equality, or cache the deparsed result to avoid redundant work.

Copilot uses AI. Check for mistakes.
@tianzhou tianzhou force-pushed the view_logic_expr_followup branch from 479958f to 3553498 Compare October 15, 2025 17:51
@tianzhou tianzhou merged commit ea77eba into main Oct 15, 2025
2 checks passed
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.

2 participants