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

Method formatHideConstants

pkg/sql/sem/tree/hide_constants.go:138–165  ·  view source on GitHub ↗

formatHideConstants formats array expressions containing only literals or placeholders and longer than 1 element as an array expression of its first two elements, scrubbed. e.g. array[1] -> array[_] array[1, 2] -> array[_, _] array[1, 2, 3] -> array[_, _, __more3__] array[

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

136// array[1, 2, 3] -> array[_, _, __more3__]
137// array[1+2, 2+3, 3+4] -> array[_ + _, _ + _, _ + _]
138func (node *Array) formatHideConstants(ctx *FmtCtx) {
139 if len(node.Exprs) < 2 {
140 node.Format(ctx)
141 return
142 }
143
144 // First, determine if there are only literals/placeholders.
145 var i int
146 for i = 0; i < len(node.Exprs); i++ {
147 switch node.Exprs[i].(type) {
148 case Datum, Constant, *Placeholder:
149 continue
150 }
151 break
152 }
153 // If so, then use the special representation.
154 if i == len(node.Exprs) {
155 // We copy the node to preserve the "row" boolean flag.
156 v2 := *node
157 v2.Exprs = append(make(Exprs, 0, 3), v2.Exprs[:2]...)
158 if len(node.Exprs) > 2 {
159 v2.Exprs = append(v2.Exprs, arityIndicator(len(node.Exprs)-2))
160 }
161 v2.Format(ctx)
162 return
163 }
164 node.Format(ctx)
165}
166
167func arityIndicator(n int) Expr {
168 return NewUnresolvedName(arityString(n))

Callers

nothing calls this directly

Calls 3

FormatMethod · 0.95
arityIndicatorFunction · 0.85
FormatMethod · 0.65

Tested by

no test coverage detected