From b6b66506b3ea7a6ed9f2b949bb13d8074ef193b4 Mon Sep 17 00:00:00 2001 From: VersBinarii Date: Wed, 9 Feb 2022 01:22:21 +0100 Subject: [PATCH 1/2] Show failing test 0.002 will be encoded as 0.02 --- tests/postgres/types.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/postgres/types.rs b/tests/postgres/types.rs index 7b39de8596..0b58421448 100644 --- a/tests/postgres/types.rs +++ b/tests/postgres/types.rs @@ -421,6 +421,12 @@ test_type!(bigdecimal(Postgres, "0.01234567::numeric" == "0.01234567".parse::().unwrap(), "0.012345678::numeric" == "0.012345678".parse::().unwrap(), "0.0123456789::numeric" == "0.0123456789".parse::().unwrap(), + "0.002::numeric" == "0.002".parse::().unwrap(), + "0.0002::numeric" == "0.0002".parse::().unwrap(), + "0.00002::numeric" == "0.00002".parse::().unwrap(), + "0.000002::numeric" == "0.000002".parse::().unwrap(), + "0.0000002::numeric" == "0.0000002".parse::().unwrap(), + "0.00000002::numeric" == "0.00000002".parse::().unwrap(), "12.34::numeric" == "12.34".parse::().unwrap(), "12345.6789::numeric" == "12345.6789".parse::().unwrap(), )); From be9f4d55318e5722f9f435aa1cde0bcb5e1d551b Mon Sep 17 00:00:00 2001 From: VersBinarii Date: Wed, 9 Feb 2022 01:23:37 +0100 Subject: [PATCH 2/2] The power calculation should depend on the offset of the digits --- sqlx-core/src/postgres/types/bigdecimal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-core/src/postgres/types/bigdecimal.rs b/sqlx-core/src/postgres/types/bigdecimal.rs index 54cbf9e320..f7958bab17 100644 --- a/sqlx-core/src/postgres/types/bigdecimal.rs +++ b/sqlx-core/src/postgres/types/bigdecimal.rs @@ -115,7 +115,7 @@ impl TryFrom<&'_ BigDecimal> for PgNumeric { digits.push(base_10_to_10000(first)); } } else if offset != 0 { - digits.push(base_10_to_10000(&base_10) * 10i16.pow(3 - base_10.len() as u32)); + digits.push(base_10_to_10000(&base_10) * 10i16.pow((offset - base_10.len()) as u32)); } if let Some(rest) = base_10.get(offset..) {