MCPcopy Create free account
hub / github.com/PostHog/duckgres / formatArrayValue

Function formatArrayValue

server/conn_results.go:428–457  ·  view source on GitHub ↗

formatArrayValue formats a []any slice as PostgreSQL text array: {1,2,3}

(arr []any)

Source from the content-addressed store, hash-verified

426 // switch — see server/value_normalize.go.
427 return formatInterval(val)
428 case map[string]any:
429 // STRUCT text format: {"key1": val1, "key2": val2}
430 return formatMapValue(val)
431 case arrowmap.OrderedMapValue:
432 return formatOrderedMapValue(val)
433 default:
434 // For other types, try to convert to string
435 return fmt.Sprintf("%v", val)
436 }
437}
438
439// formatInterval formats an arrowmap.IntervalValue as a PostgreSQL-compatible
440// interval string. Examples: "00:13:08.917797", "1 day 02:30:00",
441// "1 year 2 mons 3 days 04:05:06".
442func formatInterval(iv arrowmap.IntervalValue) string {
443 var parts []string
444 if iv.Months != 0 {
445 years := iv.Months / 12
446 remMonths := iv.Months % 12
447 if years != 0 {
448 if years == 1 || years == -1 {
449 parts = append(parts, fmt.Sprintf("%d year", years))
450 } else {
451 parts = append(parts, fmt.Sprintf("%d years", years))
452 }
453 }
454 if remMonths != 0 {
455 if remMonths == 1 || remMonths == -1 {
456 parts = append(parts, fmt.Sprintf("%d mon", remMonths))
457 } else {
458 parts = append(parts, fmt.Sprintf("%d mons", remMonths))
459 }
460 }

Callers 2

formatValueFunction · 0.85
formatCopyValueMethod · 0.85

Calls 3

formatValueFunction · 0.85
needsArrayQuotingFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected