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

Function parseValue

tests/integration/compare.go:120–172  ·  view source on GitHub ↗

parseValue attempts to parse a string value into an appropriate Go type

(s string)

Source from the content-addressed store, hash-verified

118
119// parseValue attempts to parse a string value into an appropriate Go type
120func parseValue(s string) interface{} {
121 // Empty string
122 if s == "" {
123 return ""
124 }
125
126 // Boolean
127 if s == "t" || s == "true" || s == "TRUE" {
128 return true
129 }
130 if s == "f" || s == "false" || s == "FALSE" {
131 return false
132 }
133
134 // Integer - only if the string is purely numeric
135 var i int64
136 if _, err := fmt.Sscanf(s, "%d", &i); err == nil && fmt.Sprintf("%d", i) == s {
137 return i
138 }
139
140 // Float - only if it contains decimal point or scientific notation
141 if strings.Contains(s, ".") || strings.ContainsAny(s, "eE") {
142 var f float64
143 if _, err := fmt.Sscanf(s, "%f", &f); err == nil {
144 return f
145 }
146 }
147
148 // Timestamp formats - try multiple layouts
149 timestampLayouts := []string{
150 "2006-01-02 15:04:05.999999-07",
151 "2006-01-02 15:04:05.999999+00",
152 "2006-01-02 15:04:05.999999",
153 "2006-01-02 15:04:05-07",
154 "2006-01-02 15:04:05+00",
155 "2006-01-02 15:04:05",
156 "2006-01-02 15:04:05 -0700 MST",
157 "2006-01-02 15:04:05 +0000 UTC",
158 "2006-01-02T15:04:05Z",
159 "2006-01-02T15:04:05.999999Z",
160 "2006-01-02",
161 "15:04:05",
162 "15:04:05.999999",
163 }
164 for _, layout := range timestampLayouts {
165 if t, err := time.Parse(layout, s); err == nil {
166 return t
167 }
168 }
169
170 // Return as string if no other type matched
171 return s
172}
173
174// CompareQueries executes a query on both databases and compares results
175func CompareQueries(pgDB, dgDB *sql.DB, query string, opts CompareOptions) *CompareResult {

Callers 1

ExecuteQueryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected