removing decimal with precision and decimal count

This commit is contained in:
Filipriec
2026-08-24 21:31:06 +02:00
parent 16670f4375
commit 5e9b86c1fb
22 changed files with 50 additions and 467 deletions

View File

@@ -37,17 +37,12 @@ pub fn parse_decimal_exact(value: &str) -> Result<Decimal, String> {
Decimal::from_str_exact(value).map_err(|error| error.to_string())
}
/// True for the `data_type` spellings `GetTableStructure` reports for a decimal
/// column: `NUMERIC` (from `numeric` and `money`), `NUMERIC(p)` and
/// `NUMERIC(p,s)` (from `decimal(p,s)`).
/// True for the `NUMERIC` data type reported by `GetTableStructure`.
pub fn is_decimal_data_type(data_type: &str) -> bool {
data_type
.trim()
.to_ascii_uppercase()
.starts_with(DECIMAL_DATA_TYPE_PREFIX)
data_type.trim().eq_ignore_ascii_case(DECIMAL_DATA_TYPE)
}
const DECIMAL_DATA_TYPE_PREFIX: &str = "NUMERIC";
const DECIMAL_DATA_TYPE: &str = "NUMERIC";
#[cfg(test)]
mod tests {
@@ -101,11 +96,10 @@ mod tests {
}
#[test]
fn decimal_data_type_covers_every_numeric_spelling() {
for data_type in ["NUMERIC", "NUMERIC(12)", "NUMERIC(12,3)", "numeric(12,3)"] {
assert!(is_decimal_data_type(data_type), "missed {data_type}");
}
for data_type in ["TEXT", "INT8", "TIMESTAMPTZ", "VARCHAR(255)", ""] {
fn decimal_data_type_matches_only_unconstrained_numeric() {
assert!(is_decimal_data_type("NUMERIC"));
assert!(is_decimal_data_type("numeric"));
for data_type in ["NUMERIC(12)", "NUMERIC(12,3)", "TEXT", "INT8", ""] {
assert!(!is_decimal_data_type(data_type), "matched {data_type}");
}
}