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

Method pgwireFormat

pkg/sql/sem/tree/pgwire_encode.go:79–127  ·  view source on GitHub ↗
(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

77}
78
79func (d *DArray) pgwireFormat(ctx *FmtCtx) {
80 // When converting an array to text in "postgres mode" there is
81 // special behavior: values are printed in "postgres mode" then the
82 // result string itself is rendered in "postgres mode".
83 // Immediate NULL array elements are printed as "NULL".
84 //
85 // In this last conversion, for *arrays* the special double quote
86 // and backslash characters are *escaped* (not doubled). Other
87 // special characters from C like \t \n etc are not escaped and
88 // instead printed as-is. Only non-valid characters get escaped to
89 // hex. So we delegate this formatting to a tuple-specific
90 // string printer called pgwireFormatStringInArray().
91 switch d.ResolvedType().Oid() {
92 case oid.T_int2vector, oid.T_oidvector:
93 // vectors are serialized as a string of space-separated values.
94 sep := ""
95 // TODO(justin): add a test for nested arrays when #32552 is
96 // addressed.
97 for _, d := range d.Array {
98 ctx.WriteString(sep)
99 ctx.FormatNode(d)
100 sep = " "
101 }
102 return
103 }
104
105 ctx.WriteByte('{')
106 comma := ""
107 for _, v := range d.Array {
108 ctx.WriteString(comma)
109 switch dv := UnwrapDatum(nil, v).(type) {
110 case dNull:
111 ctx.WriteString("NULL")
112 case *DString:
113 pgwireFormatStringInArray(&ctx.Buffer, string(*dv))
114 case *DCollatedString:
115 pgwireFormatStringInArray(&ctx.Buffer, dv.Contents)
116 // Bytes cannot use the default case because they will be incorrectly
117 // double escaped.
118 case *DBytes:
119 ctx.FormatNode(dv)
120 default:
121 s := AsStringWithFlags(v, ctx.flags)
122 pgwireFormatStringInArray(&ctx.Buffer, s)
123 }
124 comma = ","
125 }
126 ctx.WriteByte('}')
127}
128
129var tupleQuoteSet, arrayQuoteSet asciiSet
130

Callers 1

FormatMethod · 0.95

Calls 6

ResolvedTypeMethod · 0.95
UnwrapDatumFunction · 0.85
AsStringWithFlagsFunction · 0.85
OidMethod · 0.80
FormatNodeMethod · 0.80

Tested by

no test coverage detected