MCPcopy Index your code
hub / github.com/lib/pq / textDecode

Function textDecode

encode.go:99–136  ·  view source on GitHub ↗
(ps *parameterStatus, s []byte, typ oid.Oid)

Source from the content-addressed store, hash-verified

97}
98
99func textDecode(ps *parameterStatus, s []byte, typ oid.Oid) (any, error) {
100 switch typ {
101 case oid.T_char, oid.T_bpchar, oid.T_varchar, oid.T_text:
102 return string(s), nil
103 case oid.T_bytea:
104 b, err := parseBytea(s)
105 if err != nil {
106 err = errors.New("pq: " + err.Error())
107 }
108 return b, err
109 case oid.T_timestamptz:
110 return parseTS(ps.currentLocation, string(s))
111 case oid.T_timestamp, oid.T_date:
112 return parseTS(nil, string(s))
113 case oid.T_time:
114 return parseTime(typ, s)
115 case oid.T_timetz:
116 return parseTime(typ, s)
117 case oid.T_bool:
118 return s[0] == 't', nil
119 case oid.T_int8, oid.T_int4, oid.T_int2:
120 i, err := strconv.ParseInt(string(s), 10, 64)
121 if err != nil {
122 err = errors.New("pq: " + err.Error())
123 }
124 return i, err
125 case oid.T_float4, oid.T_float8:
126 // We always use 64 bit parsing, regardless of whether the input text is for
127 // a float4 or float8, because clients expect float64s for all float datatypes
128 // and returning a 32-bit parsed float64 produces lossy results.
129 f, err := strconv.ParseFloat(string(s), 64)
130 if err != nil {
131 err = errors.New("pq: " + err.Error())
132 }
133 return f, err
134 }
135 return s, nil
136}
137
138// appendEncodedText encodes item in text format as required by COPY
139// and appends to buf

Callers 1

decodeFunction · 0.85

Calls 4

parseByteaFunction · 0.85
parseTSFunction · 0.85
parseTimeFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…