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

Method normalize

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

Source from the content-addressed store, hash-verified

27}
28
29func (expr *CoalesceExpr) normalize(v *NormalizeVisitor) TypedExpr {
30 // This normalization checks whether COALESCE can be simplified
31 // based on constant expressions at the start of the COALESCE
32 // argument list. All known-null constant arguments are simply
33 // removed, and any known-nonnull constant argument before
34 // non-constant argument cause the entire COALESCE expression to
35 // collapse to that argument.
36 last := len(expr.Exprs) - 1
37 for i := range expr.Exprs {
38 subExpr := expr.TypedExprAt(i)
39
40 if i == last {
41 return subExpr
42 }
43
44 if !v.isConst(subExpr) {
45 exprCopy := *expr
46 exprCopy.Exprs = expr.Exprs[i:]
47 return &exprCopy
48 }
49
50 val, err := subExpr.Eval(v.ctx)
51 if err != nil {
52 v.err = err
53 return expr
54 }
55
56 if val != DNull {
57 return subExpr
58 }
59 }
60 return expr
61}
62
63func (expr *IfExpr) normalize(v *NormalizeVisitor) TypedExpr {
64 if v.isConst(expr.Cond) {

Callers

nothing calls this directly

Calls 3

TypedExprAtMethod · 0.95
EvalMethod · 0.65
isConstMethod · 0.45

Tested by

no test coverage detected