Debian Codegraph @

src/types/bigdecimal-range.md

raw symbols SCIP
1 #### Note: `BigDecimal` Has a Larger Range than `NUMERIC`
2 `BigDecimal` can represent values with a far, far greater range than the `NUMERIC` type in Postgres can.
3
4 `NUMERIC` is limited to 131,072 digits before the decimal point, and 16,384 digits after it.
5 See [Section 8.1, Numeric Types] of the Postgres manual for details.
6
7 Meanwhile, `BigDecimal` can theoretically represent a value with an arbitrary number of decimal digits, albeit
8 with a maximum of 2<sup>63</sup> significant figures.
9
10 Because encoding in the current API design _must_ be infallible,
11 when attempting to encode a `BigDecimal` that cannot fit in the wire representation of `NUMERIC`,
12 SQLx may instead encode a sentinel value that falls outside the allowed range but is still representable.
13
14 This will cause the query to return a `DatabaseError` with code `22P03` (`invalid_binary_representation`)
15 and the error message `invalid scale in external "numeric" value` (though this may be subject to change).
16
17 However, `BigDecimal` should be able to decode any `NUMERIC` value except `NaN`,
18 for which it has no representation.
19
20 [Section 8.1, Numeric Types]: https://www.postgresql.org/docs/current/datatype-numeric.html