(ctx *FmtCtx)
| 119 | } |
| 120 | |
| 121 | func (d *DArray) pgwireFormat(ctx *FmtCtx) { |
| 122 | // When converting an array to text in "postgres mode" there is |
| 123 | // special behavior: values are printed in "postgres mode" then the |
| 124 | // result string itself is rendered in "postgres mode". |
| 125 | // Immediate NULL array elements are printed as "NULL". |
| 126 | // |
| 127 | // In this last conversion, for *arrays* the special double quote |
| 128 | // and backslash characters are *escaped* (not doubled). Other |
| 129 | // special characters from C like \t \n etc are not escaped and |
| 130 | // instead printed as-is. Only non-valid characters get escaped to |
| 131 | // hex. So we delegate this formatting to a tuple-specific |
| 132 | // string printer called pgwireFormatStringInArray(). |
| 133 | switch d.ResolvedType().Oid() { |
| 134 | case oid.T_int2vector, oid.T_oidvector: |
| 135 | // vectors are serialized as a string of space-separated values. |
| 136 | sep := "" |
| 137 | // TODO(justin): add a test for nested arrays when #32552 is |
| 138 | // addressed. |
| 139 | for _, d := range d.Array { |
| 140 | ctx.WriteString(sep) |
| 141 | ctx.FormatNode(d) |
| 142 | sep = " " |
| 143 | } |
| 144 | return |
| 145 | } |
| 146 | |
| 147 | if ctx.HasFlags(fmtPGCatalog) { |
| 148 | ctx.WriteByte('\'') |
| 149 | } |
| 150 | ctx.WriteByte('{') |
| 151 | delimiter := "" |
| 152 | for _, v := range d.Array { |
| 153 | ctx.WriteString(delimiter) |
| 154 | switch dv := UnwrapDOidWrapper(v).(type) { |
| 155 | case dNull: |
| 156 | ctx.WriteString("NULL") |
| 157 | case *DString: |
| 158 | pgwireFormatStringInArray(ctx, string(*dv)) |
| 159 | case *DCollatedString: |
| 160 | pgwireFormatStringInArray(ctx, dv.Contents) |
| 161 | // Bytes cannot use the default case because they will be incorrectly |
| 162 | // double escaped. |
| 163 | case *DBytes: |
| 164 | ctx.WriteString(`"\`) |
| 165 | ctx.FormatNode(dv) |
| 166 | ctx.WriteString(`"`) |
| 167 | case *DFloat: |
| 168 | fl := float64(*dv) |
| 169 | floatTyp := d.ResolvedType().ArrayContents() |
| 170 | b := PgwireFormatFloat(nil /*buf*/, fl, ctx.dataConversionConfig, floatTyp) |
| 171 | ctx.WriteString(string(b)) |
| 172 | case *DJSON: |
| 173 | flags := ctx.flags | fmtRawStrings |
| 174 | s := AsStringWithFlags(v, flags, FmtDataConversionConfig(ctx.dataConversionConfig), FmtLocation(ctx.location)) |
| 175 | pgwireFormatStringInArray(ctx, s) |
| 176 | default: |
| 177 | s := AsStringWithFlags(v, ctx.flags, FmtDataConversionConfig(ctx.dataConversionConfig), FmtLocation(ctx.location)) |
| 178 | pgwireFormatStringInArray(ctx, s) |
no test coverage detected