Re: int4, int8, real ....division... - Mailing list pgsql-bugs

From Neil Conway
Subject Re: int4, int8, real ....division...
Date
Msg-id 40ADDD05.4090104@samurai.com
Whole thread Raw
In response to Re: int4, int8, real ....division...  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: int4, int8, real ....division...  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
Tom Lane wrote:
> This isn't a division problem --- the difficulty is there's no check for
> overflow in int4 multiplication.  (Nor in any of the other integer
> arithmetic operations, for that matter.)

It seems to me that SQL2003, Section 6.26 (<numeric value expression>,
"General Rules", item 5) requires that we check for overflow after
arithmetic operations on exact numeric types:

%%%%
5) If the most specific type of the result of an arithmetic operation is
exact numeric, then

Case:

a) If the operator is not division and the mathematical result of the
operation is not exactly representable with the precision and scale of
the result data type, then an exception condition is raised: data
exception — numeric value out of range.

b) If the operator is division and the approximate mathematical result
of the operation represented with the precision and scale of the result
data type loses one or more leading significant digits after rounding or
truncating if necessary, then an exception condition is raised: data
exception — numeric value out of range. The choice of whether to round
or truncate is implementation-defined.
%%%%

Or am I misreading the spec?

-Neil

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: LATIN2 'bssz' and 'bszsz' fails on unique index
Next
From: Tom Lane
Date:
Subject: Re: int4, int8, real ....division...