MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / Format

Method Format

pkg/sql/sem/tree/datum.go:856–882  ·  view source on GitHub ↗

Format implements the NodeFormatter interface.

(ctx *FmtCtx)

Source from the content-addressed store, hash-verified

854
855// Format implements the NodeFormatter interface.
856func (d *DFloat) Format(ctx *FmtCtx) {
857 fl := float64(*d)
858
859 disambiguate := ctx.flags.HasFlags(fmtDisambiguateDatumTypes)
860 parsable := ctx.flags.HasFlags(FmtParsableNumerics)
861 quote := parsable && (math.IsNaN(fl) || math.IsInf(fl, 0))
862 // We need to use Signbit here and not just fl < 0 because of -0.
863 needParens := !quote && (disambiguate || parsable) && math.Signbit(fl)
864 // If the number is negative, we need to use parens or the `:::INT` type hint
865 // will take precedence over the negation sign.
866 if quote {
867 ctx.WriteByte('\'')
868 } else if needParens {
869 ctx.WriteByte('(')
870 }
871 if _, frac := math.Modf(fl); frac == 0 && -1000000 < *d && *d < 1000000 {
872 // d is a small whole number. Ensure it is printed using a decimal point.
873 ctx.Printf("%.1f", fl)
874 } else {
875 ctx.Printf("%g", fl)
876 }
877 if quote {
878 ctx.WriteByte('\'')
879 } else if needParens {
880 ctx.WriteByte(')')
881 }
882}
883
884// Size implements the Datum interface.
885func (d *DFloat) Size() uintptr {

Callers

nothing calls this directly

Calls 2

PrintfMethod · 0.80
HasFlagsMethod · 0.45

Tested by

no test coverage detected