pub struct Decimal { /* private fields */ }Expand description
A DuckDB DECIMAL(width, scale) value.
value stores the scaled integer payload. For example,
123.45::DECIMAL(9, 2) is represented as
Decimal::new(9, 2, 12345)?.
The declared width is preserved when reading and writing DuckDB DECIMAL
columns. Values converted from non-decimal sources, such as integers or
rust_decimal values, infer the smallest width that can represent the
scaled payload. Width is not part of equality or hashing: values with the
same scale and scaled integer payload compare equal even if they arrived
through paths with different declared widths. Use Decimal::width when
the declared width matters; Eq and Hash do not preserve it.
Scale is part of identity: DECIMAL(2, 1) with payload 12 and
DECIMAL(3, 2) with payload 120 compare different. Decimal
intentionally does not implement Ord or PartialOrd; sort in SQL or
compare an explicitly normalized representation when ordering is needed.
Implementations§
Source§impl Decimal
impl Decimal
Sourcepub fn new(width: u8, scale: u8, value: i128) -> Result<Self, DecimalError>
pub fn new(width: u8, scale: u8, value: i128) -> Result<Self, DecimalError>
Builds a valid DECIMAL(width, scale) wrapper.
Returns DecimalError when width is outside DuckDB’s 1..=38
range, scale is larger than width, or value has more digits than
width allows.