Skip to main content

numeric

Function numeric 

Source
pub fn numeric(value: Decimal, precision: u8, scale: u8) -> Numeric
Expand description

Create a decimal/numeric parameter with explicit precision and scale.

Required when binding to an Always Encrypted decimal column, whose declared decimal(precision, scale) must match the column exactly.

numeric(value, precision, scale) asserts that value fits the decimal(precision, scale) domain, and ToSql::to_sql enforces that assertion on every path — encrypted or plaintext (it is the caller’s declared domain, not a property of the connection). It errors when:

  • precision is outside 1..=38, or scale > precision;
  • scale > 28rust_decimal::Decimal caps its backing scale at 28, so a larger declared scale cannot be represented and, on the Always Encrypted path, would emit a magnitude a Microsoft client reads at the wrong scale (e.g. 0.50.005) with no server backstop. The driver’s decimal Always Encrypted support is therefore bounded to scale ≤ 28;
  • the value, after rescaling, has more significant digits than precision.

The value is rescaled to scale, which rounds when the value has more fractional digits than scale (e.g. numeric(dec!(12.999), 18, 2) stores 13.00).