Thread: double precision to numeric overflow error

double precision to numeric overflow error

From
Thomas O'Connell
Date:
is this expected behavior? if so, then why?

-tfo

db=# create table foo( col timestamp );
db=# select cast( extract( epoch from col ) as numeric( 15, 6 ) ) from
foo;
 date_part
-----------
(0 rows)
db=# insert into foo values( current_timestamp );
INSERT 1705954 1
db=# select cast( extract( epoch from col ) as numeric( 15, 6 ) ) from
foo;
ERROR:  overflow on numeric ABS(value) >= 10^9 for field with precision
15 scale 6

Re: double precision to numeric overflow error

From
Stephan Szabo
Date:
On Tue, 7 Jan 2003, Thomas O'Connell wrote:

> is this expected behavior? if so, then why?

I'd guess so if the timestamp value's integer part is
10 digits long since I believe trying to fit that into
a numeric(15,6) wouldn't work (9 digits . 6 digits).

> db=# create table foo( col timestamp );
> db=# select cast( extract( epoch from col ) as numeric( 15, 6 ) ) from
> foo;
>  date_part
> -----------
> (0 rows)
> db=# insert into foo values( current_timestamp );
> INSERT 1705954 1
> db=# select cast( extract( epoch from col ) as numeric( 15, 6 ) ) from
> foo;
> ERROR:  overflow on numeric ABS(value) >= 10^9 for field with precision
> 15 scale 6




Re: double precision to numeric overflow error

From
Thomas O'Connell
Date:
Indeed, it seems as though my inability to count digits was the real
problem. Still, does this not strike anyone as a somewhat abstruse error
message?

-tfo

In article <20030107152951.R67168-100000@megazone23.bigpanda.com>,
 sszabo@megazone23.bigpanda.com (Stephan Szabo) wrote:

> On Tue, 7 Jan 2003, Thomas O'Connell wrote:
>
> > is this expected behavior? if so, then why?
>
> I'd guess so if the timestamp value's integer part is
> 10 digits long since I believe trying to fit that into
> a numeric(15,6) wouldn't work (9 digits . 6 digits).
>
> > db=# create table foo( col timestamp );
> > db=# select cast( extract( epoch from col ) as numeric( 15, 6 ) ) from
> > foo;
> >  date_part
> > -----------
> > (0 rows)
> > db=# insert into foo values( current_timestamp );
> > INSERT 1705954 1
> > db=# select cast( extract( epoch from col ) as numeric( 15, 6 ) ) from
> > foo;
> > ERROR:  overflow on numeric ABS(value) >= 10^9 for field with precision
> > 15 scale 6

Re: [GENERAL] double precision to numeric overflow error

From
Tom Lane
Date:
"Thomas O'Connell" <tfo@monsterlabs.com> writes:
> Indeed, it seems as though my inability to count digits was the real
> problem. Still, does this not strike anyone as a somewhat abstruse error
> message?

How would you phrase it?

> ERROR:  overflow on numeric ABS(value) >= 10^9 for field with precision
> 15 scale 6

It's technically correct, but if you think you can word it better,
let's see your proposal...

            regards, tom lane

Re: double precision to numeric overflow error

From
Thomas O'Connell
Date:
Well, it would've immediately (rather than the several minutes it took)
given away the problem if it read something like:

ERROR:  overflow caused by cast of double precision value to numeric
without sufficient precision, scale (15, 6)

or even, depending on how much detail is available or how much worth
assigned to error reporting:

ERROR:  a double precision value requiring at least precision 16 cannot
be cast to a numeric value with precision 15, scale 6.

i understand the need for balancing correctness with readability,
though. if there's anything technically incorrect about either of my
proprosals, they clearly should not be used.

i'm usually a fan of breaking error messages down as far as the details
will allow them to be correctly broken down.

in this situtation, it seems like it is this specific cast (double
precision -> numeric) in this specific scenario (insufficient precision)
that generates the error.

unfortunately, i haven't read the code... :(

-tfo

In article <726.1041999309@sss.pgh.pa.us>, tgl@sss.pgh.pa.us (Tom Lane)
wrote:

> "Thomas O'Connell" <tfo@monsterlabs.com> writes:
> > Indeed, it seems as though my inability to count digits was the real
> > problem. Still, does this not strike anyone as a somewhat abstruse error
> > message?
>
> How would you phrase it?
>
> > ERROR:  overflow on numeric ABS(value) >= 10^9 for field with precision
> > 15 scale 6
>
> It's technically correct, but if you think you can word it better,
> let's see your proposal...

Re: [GENERAL] double precision to numeric overflow error

From
Jan Wieck
Date:
Thomas O'Connell wrote:
>
> Well, it would've immediately (rather than the several minutes it took)
> given away the problem if it read something like:
>
> ERROR:  overflow caused by cast of double precision value to numeric
> without sufficient precision, scale (15, 6)
>
> or even, depending on how much detail is available or how much worth
> assigned to error reporting:

The message will be exactly the same in all cases, since there is no
more detail. I think words about casting and such could be fairly
confusing in the case someone just inserts a literal value - no?


Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #