MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / PgwireFormatFloat

Function PgwireFormatFloat

pkg/sql/sem/tree/pgwire_encode.go:204–221  ·  view source on GitHub ↗

PgwireFormatFloat returns a []byte representing a float according to pgwire encoding. The result is appended to the given buffer.

(
	buf []byte, fl float64, conv sessiondatapb.DataConversionConfig, floatTyp *types.T,
)

Source from the content-addressed store, hash-verified

202// PgwireFormatFloat returns a []byte representing a float according to
203// pgwire encoding. The result is appended to the given buffer.
204func PgwireFormatFloat(
205 buf []byte, fl float64, conv sessiondatapb.DataConversionConfig, floatTyp *types.T,
206) []byte {
207 // PostgreSQL supports 'Inf' as a valid literal for the floating point
208 // special value Infinity, therefore handling the special cases for them.
209 // (https://github.com/cockroachdb/cockroachdb-parser/issues/62601)
210 if math.IsInf(fl, 1) {
211 return append(buf, []byte("Infinity")...)
212 } else if math.IsInf(fl, -1) {
213 return append(buf, []byte("-Infinity")...)
214 } else {
215 return strconv.AppendFloat(
216 buf, fl, 'g',
217 conv.GetFloatPrec(floatTyp),
218 int(floatTyp.Width()),
219 )
220 }
221}
222
223func pgwireQuoteStringInTuple(in string) bool {
224 return in == "" || tupleQuoteSet.in(in)

Callers 3

pgwireFormatMethod · 0.85
pgwireFormatMethod · 0.85
FormatMethod · 0.85

Calls 2

GetFloatPrecMethod · 0.80
WidthMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…