From: John Dickson <jdickson@tnsi.com>
To: pgsql-bugs@postgresql.org
Subject: BUG #5975: Incorrect result from mod function with cast
Date: Wed, 13 Apr 2011 00:30:12 GMT
Message-ID: <201104130030.p3D0UCSZ076614@wwwmaster.postgresql.org> (raw)
The following bug has been logged online:
Bug reference: 5975
Logged by: John Dickson
Email address: jdickson@tnsi.com
PostgreSQL version: 8.3.11
Operating system: RedHat EL 5.6
Description: Incorrect result from mod function with cast
Details:
The mod function (and the % operator) can return an incorrect result when
combined with a cast().
The following SQL (executed on 8.3.11) shows a result one higher than the
maximum permissible remainder when combined with a cast:
-----
select 1129590 % 66,
cast(1129590 as numeric(21, 0)) % 66;
?column? | ?column?
----------+----------
0 | 66
(1 row)
-----
When executed on Postgres 8.2.5 (on Centos 4.6), the results are:
-----
?column? | ?column?
----------+----------
0 | 0
(1 row)
-----
We're using the cast here to demonstrate the bug, but we actually strike the
problem when operating on values from a numeric(21, 0) column rather than
using cast().
We haven't tested this on later releases of 8.3, but didn't see any likely
fixes in the changelog.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: jdickson@tnsi.com
Subject: Re: BUG #5975: Incorrect result from mod function with cast
In-Reply-To: <201104130030.p3D0UCSZ076614@wwwmaster.postgresql.org>
References: <201104130030.p3D0UCSZ076614@wwwmaster.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox