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

Function pgNumberFormatToDuckDB

transpiler/transform/functions.go:635–667  ·  view source on GitHub ↗

pgNumberFormatToDuckDB converts PostgreSQL number format specifiers to DuckDB format() syntax. PG format: '999,999.99' → DuckDB: '{:,.2f}'

(pgFormat string)

Source from the content-addressed store, hash-verified

633// pgNumberFormatToDuckDB converts PostgreSQL number format specifiers to DuckDB format() syntax.
634// PG format: '999,999.99' → DuckDB: '{:,.2f}'
635func pgNumberFormatToDuckDB(pgFormat string) string {
636 upper := strings.ToUpper(strings.ReplaceAll(strings.ReplaceAll(pgFormat, "FM", ""), "fm", ""))
637
638 hasComma := strings.ContainsAny(upper, ",G")
639
640 // Count decimal places (digits after . or D)
641 decimalPlaces := 0
642 dotIdx := strings.IndexAny(upper, ".D")
643 if dotIdx >= 0 {
644 for i := dotIdx + 1; i < len(upper); i++ {
645 if upper[i] == '9' || upper[i] == '0' {
646 decimalPlaces++
647 }
648 }
649 }
650
651 commaFlag := ""
652 if hasComma {
653 commaFlag = ","
654 }
655
656 prefix := ""
657 if strings.Contains(upper, "$") || strings.Contains(upper, "L") {
658 prefix = "$"
659 }
660
661 // Check for EEEE (scientific notation)
662 if strings.Contains(upper, "EEEE") {
663 return fmt.Sprintf("%s{:%s.%de}", prefix, commaFlag, decimalPlaces)
664 }
665
666 return fmt.Sprintf("%s{:%s.%df}", prefix, commaFlag, decimalPlaces)
667}

Callers 1

handleToCharMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected