On Thu, Sep 28, 2006 at 11:16:56PM +0200, Martijn van Oosterhout wrote:
> On Thu, Sep 28, 2006 at 05:11:43PM -0400, Tom Lane wrote:
> > David Fetter <[EMAIL PROTECTED]> writes:
> > > ! DETAIL:  A field with precision 4, scale 4 must have an absolute value 
> > > less than 1.
> > > [ becomes ]
> > > ! DETAIL:  A field with precision 4, scale 4 must have an absolute value 
> > > less than 1 - 5 * 10^-5.
> > 
> > This strikes me as overly pedantic.  The message needs to be clear,
> > and the proposed change will just confuse people.
> 
> I don't know if the code can detect the difference, but a message like:
> 
> A field with precision 4, scale 4 must *round to* an absolute value less than 
> 1
> 
> Since that more accurately describes the actual problem.
> 
> Have a ncie day,

Per your suggestion, how about this patch?

Cheers,
D
-- 
David Fetter <[EMAIL PROTECTED]> http://fetter.org/
phone: +1 415 235 3778        AIM: dfetter666
                              Skype: davidfetter

Remember to vote!
? correct_numeric_overflow_error.patch
? contrib/plparrot
? contrib/plparrot.tar.bz2
Index: src/backend/utils/adt/numeric.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/numeric.c,v
retrieving revision 1.94
diff -c -r1.94 numeric.c
*** src/backend/utils/adt/numeric.c     14 Jul 2006 05:28:28 -0000      1.94
--- src/backend/utils/adt/numeric.c     2 Oct 2006 00:35:47 -0000
***************
*** 3217,3227 ****
                                        ereport(ERROR,
                                                        
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                                                         errmsg("numeric field 
overflow"),
!                                                        errdetail("A field 
with precision %d, scale %d must have an absolute value less than %s%d.",
                                                                           
precision, scale,
                                                                           /* 
Display 10^0 as 1 */
                                                                           
maxdigits ? "10^" : "",
!                                                                          
maxdigits ? maxdigits : 1)));
                                break;
                        }
                        ddigits -= DEC_DIGITS;
--- 3217,3228 ----
                                        ereport(ERROR,
                                                        
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                                                         errmsg("numeric field 
overflow"),
!                                                        errdetail("A field 
with precision %d, scale %d must round to an absolute value less than %s%d.",
                                                                           
precision, scale,
                                                                           /* 
Display 10^0 as 1 */
                                                                           
maxdigits ? "10^" : "",
!                                                                          
maxdigits ? maxdigits : 1
!                                                                          )));
                                break;
                        }
                        ddigits -= DEC_DIGITS;
Index: src/test/regress/expected/numeric.out
===================================================================
RCS file: /projects/cvsroot/pgsql/src/test/regress/expected/numeric.out,v
retrieving revision 1.18
diff -c -r1.18 numeric.out
*** src/test/regress/expected/numeric.out       25 Jan 2006 18:20:22 -0000      
1.18
--- src/test/regress/expected/numeric.out       2 Oct 2006 00:35:47 -0000
***************
*** 688,699 ****
  INSERT INTO fract_only VALUES (2, '0.1');
  INSERT INTO fract_only VALUES (3, '1.0');     -- should fail
  ERROR:  numeric field overflow
! DETAIL:  A field with precision 4, scale 4 must have an absolute value less 
than 1.
  INSERT INTO fract_only VALUES (4, '-0.9999');
  INSERT INTO fract_only VALUES (5, '0.99994');
  INSERT INTO fract_only VALUES (6, '0.99995');  -- should fail
  ERROR:  numeric field overflow
! DETAIL:  A field with precision 4, scale 4 must have an absolute value less 
than 1.
  INSERT INTO fract_only VALUES (7, '0.00001');
  INSERT INTO fract_only VALUES (8, '0.00017');
  SELECT * FROM fract_only;
--- 688,699 ----
  INSERT INTO fract_only VALUES (2, '0.1');
  INSERT INTO fract_only VALUES (3, '1.0');     -- should fail
  ERROR:  numeric field overflow
! DETAIL:  A field with precision 4, scale 4 must round to an absolute value 
less than 1.
  INSERT INTO fract_only VALUES (4, '-0.9999');
  INSERT INTO fract_only VALUES (5, '0.99994');
  INSERT INTO fract_only VALUES (6, '0.99995');  -- should fail
  ERROR:  numeric field overflow
! DETAIL:  A field with precision 4, scale 4 must round to an absolute value 
less than 1.
  INSERT INTO fract_only VALUES (7, '0.00001');
  INSERT INTO fract_only VALUES (8, '0.00017');
  SELECT * FROM fract_only;
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

Reply via email to