MCPcopy Create free account
hub / github.com/dolthub/doltgresql / ArrToString

Function ArrToString

server/types/utils.go:164–186  ·  view source on GitHub ↗

ArrToString is used for array_out function. |trimBool| parameter allows replacing boolean result of "true" to "t" if the function is `Type.SQL()`.

(ctx *sql.Context, arr []any, baseType *DoltgresType, trimBool bool)

Source from the content-addressed store, hash-verified

162// ArrToString is used for array_out function. |trimBool| parameter allows replacing
163// boolean result of "true" to "t" if the function is `Type.SQL()`.
164func ArrToString(ctx *sql.Context, arr []any, baseType *DoltgresType, trimBool bool) (string, error) {
165 sb := strings.Builder{}
166 sb.WriteRune('{')
167 for i, v := range arr {
168 if i > 0 {
169 sb.WriteString(",")
170 }
171 if v != nil {
172 str, err := baseType.IoOutput(ctx, v)
173 if err != nil {
174 return "", err
175 }
176 if baseType.ID == Bool.ID && trimBool {
177 str = string(str[0])
178 }
179 sb.WriteString(quoteString(str))
180 } else {
181 sb.WriteString("NULL")
182 }
183 }
184 sb.WriteRune('}')
185 return sb.String(), nil
186}
187
188// RecordToString is used for the record_out function, to serialize record values for wire transfer.
189// |fields| contains the values to serialize.

Callers 1

sqlStringFunction · 0.85

Calls 4

quoteStringFunction · 0.85
WriteStringMethod · 0.80
IoOutputMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected