MCPcopy Create free account
hub / github.com/bytebase/bytebase / padZeroes

Function padZeroes

backend/plugin/db/pg/query.go:186–213  ·  view source on GitHub ↗

Padding 0's to nanosecond precision to make sure it's always 6 digits. Since the data cannot be formatted into a time.Time, we need to pad it here. Accuracy is passed as argument since we cannot determine the precision of the data type using DecimalSize().

(rawStr string, acc int)

Source from the content-addressed store, hash-verified

184// Since the data cannot be formatted into a time.Time, we need to pad it here.
185// Accuracy is passed as argument since we cannot determine the precision of the data type using DecimalSize().
186func padZeroes(rawStr string, acc int) string {
187 dotIndex := strings.Index(rawStr, ".")
188 if dotIndex < 0 {
189 return rawStr
190 }
191 // End index is used to cut off the time zone information.
192 endIndex := len(rawStr)
193 if plusIndex := strings.Index(rawStr, "+"); plusIndex >= 0 {
194 endIndex = plusIndex
195 } else if minusIndex := strings.Index(rawStr, "-"); minusIndex >= 0 {
196 // For negative intervals like "-00:04:37.530865", ignore the leading minus
197 // Only consider minus signs that appear after the decimal point (timezone indicators)
198 if minusIndex > dotIndex {
199 endIndex = minusIndex
200 }
201 }
202
203 // Validate slice bounds to prevent runtime panic
204 if endIndex <= dotIndex {
205 return rawStr
206 }
207
208 decimalPart := rawStr[dotIndex+1 : endIndex]
209 if len(decimalPart) < acc {
210 rawStr = rawStr[:endIndex] + strings.Repeat("0", acc-len(decimalPart)) + rawStr[endIndex:]
211 }
212 return rawStr
213}
214
215// getStatementWithResultLimit returns the statement with LIMIT clause if not exists.
216func getStatementWithResultLimit(statement string, limit int) string {

Callers 2

convertValueFunction · 0.70
TestPadZeroesFunction · 0.70

Calls

no outgoing calls

Tested by 1

TestPadZeroesFunction · 0.56