double precision to numeric overflow error

Started by Thomas F. O'Connellover 23 years ago6 messagesgeneral
Jump to latest
#1Thomas F. O'Connell
tfo@monsterlabs.com

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

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Thomas F. O'Connell (#1)
Re: [SQL] double precision to numeric overflow error

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).

Show quoted text

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

#3Thomas F. O'Connell
tfo@monsterlabs.com
In reply to: Stephan Szabo (#2)
Re: double precision to numeric overflow error

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:

Show quoted text

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

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thomas F. O'Connell (#3)
Re: double precision to numeric overflow error

"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

#5Thomas F. O'Connell
tfo@monsterlabs.com
In reply to: Tom Lane (#4)
Re: double precision to numeric overflow error

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:

Show quoted text

"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...

#6Jan Wieck
JanWieck@Yahoo.com
In reply to: Tom Lane (#4)
Re: double precision to numeric overflow error

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 #