(ctx *FmtCtx)
| 77 | } |
| 78 | |
| 79 | func (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 | |
| 129 | var tupleQuoteSet, arrayQuoteSet asciiSet |
| 130 |
no test coverage detected