MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / Format

Method Format

pkg/sql/sem/tree/datum.go:5147–5172  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

5145
5146// Format implements the NodeFormatter interface.
5147func (d *DArray) Format(ctx *FmtCtx) {
5148 if ctx.flags.HasAnyFlags(fmtPgwireFormat | fmtPGCatalog) {
5149 defer func(f FmtFlags) { ctx.flags = f }(ctx.flags)
5150 ctx.flags = ctx.flags & ^fmtPGCatalogCasts
5151 ctx.flags = ctx.flags | FmtBareStrings
5152 d.pgwireFormat(ctx)
5153 return
5154 }
5155
5156 // If we want to export arrays, we need to ensure that
5157 // the datums within the arrays are formatted with enclosing quotes etc.
5158 if ctx.HasFlags(FmtExport) {
5159 oldFlags := ctx.flags
5160 ctx.flags = oldFlags & ^FmtExport | FmtParsable
5161 defer func() { ctx.flags = oldFlags }()
5162 }
5163
5164 ctx.WriteString("ARRAY[")
5165 comma := ""
5166 for _, v := range d.Array {
5167 ctx.WriteString(comma)
5168 ctx.FormatNode(v)
5169 comma = ","
5170 }
5171 ctx.WriteByte(']')
5172}
5173
5174const maxArrayLength = math.MaxInt32
5175

Callers 1

Calls 4

pgwireFormatMethod · 0.95
FormatNodeMethod · 0.80
HasAnyFlagsMethod · 0.45
HasFlagsMethod · 0.45

Tested by

no test coverage detected