Money type does not detect over/underflow unlike int/int8

From: Yasuo Ohgaki <yohgaki(at)ohgaki(dot)net>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Money type does not detect over/underflow unlike int/int8
Date: 2017-03-31 23:03:03
Message-ID: CAGa2bXZ1uQecXWbtadNt02Kf=yWE0NyG+wm7RDMZhAMLNzX8bw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi developers.

int/int8 detects over/underflow.

====================
yohgaki(at)[local] ~=> SELECT '999999999999999999999'::int8;
ERROR: 22003: value "999999999999999999999" is out of range for type bigint
行 1: SELECT '999999999999999999999'::int8;
^
LOCATION: scanint8, int8.c:115
時間: 0.176 ms
====================

However, money type does not detect over/underflow and results in strange
results.

Works within range (Tested with 9.5 and 9.6)
====================
yohgaki(at)[local] ~=> SELECT '9999999'::money;
money
---------------
$9,999,999.00
(1 行)

時間: 0.209 ms
====================

Strange results with out of range (Tested with 9.5 and 9.6)
====================
yohgaki(at)[local] ~=> SELECT '999999999999999999999'::money;
money
---------------------------
$2,003,764,205,206,895.64
(1 行)

時間: 0.149 ms
yohgaki(at)[local] ~=> SELECT '9999999999999999999999999999999999999'::money;
money
----------------------------
$68,739,955,140,067,327.00
(1 行)

時間: 0.197 ms
yohgaki(at)[local] ~=> SELECT
'9999999999999999999999999999999999999999999999999999999'::money;
money
----------------------------
$53,322,619,588,066,671.64
(1 行)

時間: 0.144 ms
yohgaki(at)[local] ~=> SELECT
'99999999999999999999999999999999999999999999999999'::money;
money
-----------------------------
-$26,616,273,797,759,632.36
(1 行)

時間: 0.226 ms
====================

--
Yasuo Ohgaki
yohgaki(at)ohgaki(dot)net

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-04-01 00:37:27 Re: BUG #14607: session variables are non-deterministic
Previous Message Paul Coyne 2017-03-31 22:47:15 Re: BUG #14609: ON CONSTRAINT (aka UPSERT) code fails when excluded.<columname> used in calculation.