postgres: emit full leading-zero groups when binary-decoding sub-1e-8 NUMERIC (#31211)
The Postgres binary NUMERIC decoder collapsed Postgres' two `get_str_from_var` counters — a base-10000 digit index and a decimal-place position — into a single index that advanced by 4 but also gated the leading-zero region. For `weight <= -3` (values below 1e-8 with no integer part) this walked the leading "0000" groups 4× too fast and dropped one or more of them, shifting every significant digit left by 4 decimals per dropped group (e.g. `1e-9` decoded as `0.000010000`). Values ≥ 1e-8, and any value with an integer part, were unaffected; text-protocol decoding was always correct. Split the two counters back apart, mirroring `get_str_from_var`: one walks the base-10000 digits, the other counts emitted decimal places and drives truncation to `dscale`. The leading-zero region now emits a full "0000" group per missing digit position. Adds a mock-Postgres-server test covering a matrix of sub-1e-8 and boundary values. (Not a port regression — the Zig decoder has the same defect, but Node/psql are correct.)
A
Alistair Smith committed
4ee835b753153de7d0ebbf3b3bbd34ed5889451b
Parent: b668561
Committed by GitHub <noreply@github.com>
on 5/27/2026, 9:25:43 PM