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

Function formatSQLValue

server/ducklake/migration.go:552–576  ·  view source on GitHub ↗

formatSQLValue formats a Go value as a SQL literal for INSERT statements. Note: []byte is treated as UTF-8 text (fine for DuckLake metadata which stores only text, integers, and booleans — no bytea columns).

(v any)

Source from the content-addressed store, hash-verified

550// Note: []byte is treated as UTF-8 text (fine for DuckLake metadata which stores
551// only text, integers, and booleans — no bytea columns).
552func formatSQLValue(v any) string {
553 if v == nil {
554 return "NULL"
555 }
556 switch val := v.(type) {
557 case bool:
558 if val {
559 return "TRUE"
560 }
561 return "FALSE"
562 case int64:
563 return fmt.Sprintf("%d", val)
564 case float64:
565 return fmt.Sprintf("%g", val)
566 case []byte:
567 return fmt.Sprintf("'%s'", strings.ReplaceAll(string(val), "'", "''"))
568 case string:
569 return fmt.Sprintf("'%s'", strings.ReplaceAll(val, "'", "''"))
570 case time.Time:
571 return fmt.Sprintf("'%s'", val.Format(time.RFC3339Nano))
572 default:
573 s := fmt.Sprintf("%v", val)
574 return fmt.Sprintf("'%s'", strings.ReplaceAll(s, "'", "''"))
575 }
576}
577
578// injectPostgresKeepalive adds TCP keepalive parameters to a postgres metadata
579// store connection string if they are not already present. Without keepalives,

Callers 2

backupTableFunction · 0.85
TestFormatSQLValueFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestFormatSQLValueFunction · 0.68