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)
| 550 | // Note: []byte is treated as UTF-8 text (fine for DuckLake metadata which stores |
| 551 | // only text, integers, and booleans — no bytea columns). |
| 552 | func 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, |
no outgoing calls