@@ -255,6 +255,43 @@ mod test {
255
255
assert_eq ! ( Decimal :: ZERO , result) ;
256
256
}
257
257
258
+ #[ test]
259
+ fn read_small_unconstrained_numeric_type ( ) {
260
+ let mut client = match Client :: connect ( & get_postgres_url ( ) , NoTls ) {
261
+ Ok ( x) => x,
262
+ Err ( err) => panic ! ( "{:#?}" , err) ,
263
+ } ;
264
+ let result: Decimal = match client. query ( "SELECT 0.100000000000000000000000000001::NUMERIC" , & [ ] ) {
265
+ Ok ( x) => x. first ( ) . unwrap ( ) . get ( 0 ) ,
266
+ Err ( err) => panic ! ( "error - {:#?}" , err) ,
267
+ } ;
268
+
269
+ // This gets rounded to 28 decimal places. In the future we may want to introduce a global feature which
270
+ // prevents rounding.
271
+ assert_eq ! ( result. to_string( ) , "0.1000000000000000000000000000" ) ;
272
+ assert_eq ! ( result. scale( ) , 28 ) ;
273
+ }
274
+
275
+ #[ test]
276
+ fn read_small_unconstrained_numeric_type_addition ( ) {
277
+ let mut client = match Client :: connect ( & get_postgres_url ( ) , NoTls ) {
278
+ Ok ( x) => x,
279
+ Err ( err) => panic ! ( "{:#?}" , err) ,
280
+ } ;
281
+ let ( a, b) : ( Decimal , Decimal ) = match client. query (
282
+ "SELECT 0.100000000000000000000000000001::NUMERIC, 0.00000000000014780214::NUMERIC" ,
283
+ & [ ] ,
284
+ ) {
285
+ Ok ( x) => {
286
+ let row = x. first ( ) . unwrap ( ) ;
287
+ ( row. get ( 0 ) , row. get ( 1 ) )
288
+ }
289
+ Err ( err) => panic ! ( "error - {:#?}" , err) ,
290
+ } ;
291
+
292
+ assert_eq ! ( a + b, Decimal :: from_str( "0.1000000000001478021400000000" ) . unwrap( ) ) ;
293
+ }
294
+
258
295
#[ test]
259
296
fn read_numeric_type ( ) {
260
297
let mut client = match Client :: connect ( & get_postgres_url ( ) , NoTls ) {
0 commit comments