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

Function quoteString

server/types/utils.go:339–352  ·  view source on GitHub ↗

quoteString determines if |s| needs to be quoted, by looking for special characters like ' ' or ',', and if so, quotes the string and returns it. If quoting is not needed, then |s| is returned as is.

(s string)

Source from the content-addressed store, hash-verified

337// quoteString determines if |s| needs to be quoted, by looking for special characters like ' ' or ',',
338// and if so, quotes the string and returns it. If quoting is not needed, then |s| is returned as is.
339func quoteString(s string) string {
340 shouldQuote := false
341 for _, r := range s {
342 switch r {
343 case ' ', ',', '{', '}', '\\', '"':
344 shouldQuote = true
345 }
346 }
347 if shouldQuote || strings.EqualFold(s, "NULL") || len(s) == 0 {
348 return fmt.Sprintf(`"%s"`, strings.ReplaceAll(s, `"`, `\"`))
349 } else {
350 return s
351 }
352}
353
354// toInternal returns an Internal ID for the given type. This is only used for the built-in types, since they all share
355// the same schema (pg_catalog).

Callers 3

ArrToStringFunction · 0.85
RecordToStringFunction · 0.85
VectorToStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected