Skip site navigation (1) Skip section navigation (2)

Re: [GENERAL] Different exponent in error messages

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Michael Fuhr <mike(at)fuhr(dot)org>, Andrus <eetasoft(at)online(dot)ee>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [GENERAL] Different exponent in error messages
Date: 2006-01-25 17:54:22
Message-ID: 200601251754.k0PHsM704930@candle.pha.pa.us (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-generalpgsql-patches
Applied.

---------------------------------------------------------------------------

Bruce Momjian wrote:
> Tom Lane wrote:
> > Michael Fuhr <mike(at)fuhr(dot)org> writes:
> > > I think this is what Andrus is seeing:
> > 
> > > test=> CREATE TABLE foo (n numeric(9,3));
> > > CREATE TABLE
> > > test=> INSERT INTO foo VALUES (1000000);
> > > ERROR:  numeric field overflow
> > > DETAIL:  The absolute value is greater than or equal to 10^6 for field with precision 9, scale 3.
> > > test=> INSERT INTO foo VALUES (1000000000);
> > > ERROR:  numeric field overflow
> > > DETAIL:  The absolute value is greater than or equal to 10^9 for field with precision 9, scale 3.
> > 
> > Hm, I thought I tested that same case, but I must've messed up somehow.
> > 
> > Anyway, the code seems to be intentionally reporting the log10 of the
> > actual input value, not the limiting log10 for the field size.  This
> > behavior goes at least as far back as PG 7.0, so I'm disinclined to
> > change it.  We could talk about altering the message wording though,
> > if you have a suggestion for something you'd find less confusing.
> > Pre-7.4 versions say
> > 
> > ERROR:  overflow on numeric ABS(value) >= 10^9 for field with precision 9 scale 3
> > 
> > so it looks like we just fixed the grammar during the 7.4 message
> > wording cleanup, without reflecting about whether the meaning was clear.
> 
> Yes, this message clearly needs help.  Here is what I developed:
> 
> 	test=> CREATE TABLE foo (n numeric(9,3));
> 	CREATE TABLE
> 	test=> INSERT INTO foo VALUES (10000000);
> 	ERROR:  numeric field overflow
> 	DETAIL:  A field with precision 9, scale 3 must have an absolute value less than 10^6.
> 
> and the 10^6 is based on the max digits to the left of the decimal
> point, not the input value.
> 
> -- 
>   Bruce Momjian                        |  http://candle.pha.pa.us
>   pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
>   +  If your life is a hard drive,     |  13 Roberts Road
>   +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

> Index: src/backend/utils/adt/numeric.c
> ===================================================================
> RCS file: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v
> retrieving revision 1.88
> diff -c -c -r1.88 numeric.c
> *** src/backend/utils/adt/numeric.c	22 Nov 2005 18:17:23 -0000	1.88
> --- src/backend/utils/adt/numeric.c	23 Jan 2006 20:00:54 -0000
> ***************
> *** 3206,3213 ****
>   					ereport(ERROR,
>   							(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
>   							 errmsg("numeric field overflow"),
> ! 							 errdetail("The absolute value is greater than or equal to 10^%d for field with precision %d, scale %d.",
> ! 									   ddigits - 1, precision, scale)));
>   				break;
>   			}
>   			ddigits -= DEC_DIGITS;
> --- 3206,3213 ----
>   					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 10^%d.",
> ! 									   precision, scale, maxdigits)));
>   				break;
>   			}
>   			ddigits -= DEC_DIGITS;

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

In response to

pgsql-patches by date

Next:From: Greg StarkDate: 2006-01-25 18:07:36
Subject: Re: [PATCHES] Adding a --quiet option to initdb
Previous:From: Bruce MomjianDate: 2006-01-25 17:33:51
Subject: Re: [PATCHES] Adding a --quiet option to initdb

pgsql-general by date

Next:From: MargaretGillonDate: 2006-01-25 17:55:58
Subject: Re: Constraint that compares and limits field values
Previous:From: andrewDate: 2006-01-25 17:52:52
Subject: Re: user defined function

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group