MCPcopy Create free account
hub / github.com/lib/pq / appendEncodedText

Function appendEncodedText

encode.go:140–160  ·  view source on GitHub ↗

appendEncodedText encodes item in text format as required by COPY and appends to buf

(buf []byte, x any)

Source from the content-addressed store, hash-verified

138// appendEncodedText encodes item in text format as required by COPY
139// and appends to buf
140func appendEncodedText(buf []byte, x any) ([]byte, error) {
141 switch v := x.(type) {
142 case int64:
143 return strconv.AppendInt(buf, v, 10), nil
144 case float64:
145 return strconv.AppendFloat(buf, v, 'f', -1, 64), nil
146 case []byte:
147 encodedBytea := encodeBytea(v)
148 return appendEscapedText(buf, string(encodedBytea)), nil
149 case string:
150 return appendEscapedText(buf, v), nil
151 case bool:
152 return strconv.AppendBool(buf, v), nil
153 case time.Time:
154 return append(buf, formatTS(v)...), nil
155 case nil:
156 return append(buf, `\N`...), nil
157 default:
158 return nil, fmt.Errorf("pq: encode: unknown type for %T", v)
159 }
160}
161
162func appendEscapedText(buf []byte, text string) []byte {
163 escapeNeeded := false

Callers 2

ExecMethod · 0.85
TestAppendEncodedTextFunction · 0.85

Calls 3

encodeByteaFunction · 0.85
appendEscapedTextFunction · 0.85
formatTSFunction · 0.85

Tested by 1

TestAppendEncodedTextFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…