Commit 56a2a81 1 parent 84d5760 commit 56a2a81 Copy full SHA for 56a2a81
File tree 1 file changed +9
-3
lines changed
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -138,12 +138,18 @@ impl TryFrom<&'_ BigDecimal> for PgNumeric {
138
138
}
139
139
}
140
140
141
- /// ### Panics
142
- /// If this `BigDecimal` cannot be represented by `PgNumeric`.
143
141
impl Encode < ' _ , Postgres > for BigDecimal {
144
142
fn encode_by_ref ( & self , buf : & mut PgArgumentBuffer ) -> IsNull {
143
+ use std:: str:: FromStr ;
144
+ // If the argument is too big, then we replace it with a less big argument.
145
+ // This less big argument is already outside the range of allowed PostgreSQL DECIMAL, which
146
+ // means that PostgreSQL will return the 22P03 error kind upon receiving it. This is the
147
+ // expected error, and the user should be ready to handle it anyway.
145
148
PgNumeric :: try_from ( self )
146
- . expect ( "BigDecimal magnitude too great for Postgres NUMERIC type" )
149
+ . unwrap_or_else ( |_| {
150
+ PgNumeric :: try_from ( & BigDecimal :: from_str ( & format ! ( "{:030000}" , 0 ) ) . unwrap ( ) )
151
+ . unwrap ( )
152
+ } )
147
153
. encode ( buf) ;
148
154
149
155
IsNull :: No
You can’t perform that action at this time.
0 commit comments