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