MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / normalize

Method normalize

pkg/sql/sem/tree/normalize.go:81–115  ·  view source on GitHub ↗
(v *NormalizeVisitor)

Source from the content-addressed store, hash-verified

79}
80
81func (expr *UnaryExpr) normalize(v *NormalizeVisitor) TypedExpr {
82 val := expr.TypedInnerExpr()
83
84 if val == DNull {
85 return val
86 }
87
88 switch expr.Operator {
89 case UnaryMinus:
90 // -0 -> 0 (except for float which has negative zero)
91 if val.ResolvedType().Family() != types.FloatFamily && v.isNumericZero(val) {
92 return val
93 }
94 switch b := val.(type) {
95 // -(a - b) -> (b - a)
96 case *BinaryExpr:
97 if b.Operator == Minus {
98 newBinExpr := newBinExprIfValidOverload(Minus,
99 b.TypedRight(), b.TypedLeft())
100 if newBinExpr != nil {
101 newBinExpr.memoizeFn()
102 b = newBinExpr
103 }
104 return b
105 }
106 // - (- a) -> a
107 case *UnaryExpr:
108 if b.Operator == UnaryMinus {
109 return b.TypedInnerExpr()
110 }
111 }
112 }
113
114 return expr
115}
116
117func (expr *BinaryExpr) normalize(v *NormalizeVisitor) TypedExpr {
118 left := expr.TypedLeft()

Callers

nothing calls this directly

Calls 9

TypedInnerExprMethod · 0.95
FamilyMethod · 0.80
isNumericZeroMethod · 0.80
ResolvedTypeMethod · 0.65
TypedRightMethod · 0.45
TypedLeftMethod · 0.45
memoizeFnMethod · 0.45
TypedInnerExprMethod · 0.45

Tested by

no test coverage detected