Skip to main content

Module float_width

Module float_width 

Source
Expand description

FloatWidth — the declared width of a floating-point column.

nodedb stores every float as a full f64 regardless of the width the DDL author declared: ColumnType::Float64 is the one storage variant for REAL, FLOAT4, DOUBLE, and FLOAT8 alike. The declared width is therefore not a storage property — it is a wire contract: the column’s RowDescription OID is 700 or 701, and under the binary result format the value is transmitted as 4 or 8 bytes. A client that declared REAL decodes exactly four bytes; handing it eight is a decode failure, not a rounding error.

§How this differs from IntWidth

The integer analogue bounds writes by full range: narrowing an out-of-range i64 wraps, so any value that does not fit a declared INTEGER is rejected at write time exactly as PostgreSQL rejects it. Floats are bounded differently. Narrowing an f64 to an f32 rounds — 1.1 becoming 1.10000002 is correct PostgreSQL real behaviour, not an error — so check_declared_float_ranges (the float counterpart of check_declared_int_ranges) never rejects on rounding. The single failure mode it does reject is overflow to infinity: a finite f64 beyond f32’s range becomes inf, which PostgreSQL raises value out of range: overflow for. That check runs at write time in the planner, mirroring the read-side guard the wire encoder applies at narrowing time — the two are deliberately layered, not redundant: the write-time check is bypassed by rows written before the column’s width was declared or via non-SQL ingest, so the read-side guard remains the backstop.

Because the keyword set is shared by catalog introspection OIDs and RowDescription OIDs alike, FloatWidth::from_declared_type is the single place that maps a declared type string to a float width, so the two can never drift apart.

Enums§

FloatWidth
The declared width of a floating-point column.