Re: [HACKERS] Numeric overflow problem + patch

Lists: pgsql-hackerspgsql-patches
From: David Fetter <david(at)fetter(dot)org>
To: PG Hackers <pgsql-hackers(at)postgresql(dot)org>, PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Numeric overflow problem + patch
Date: 2006-09-28 18:54:55
Message-ID: 20060928185455.GE22129@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Folks,

Dennis Björklund and I discovered a little problem with how CVS TIP
reports overflows on cast. Please find enclosed a patch which fixes
it.

Cheers,
D
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!

Attachment Content-Type Size
correct_numeric_overflow_error.patch text/plain 3.0 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Fetter <david(at)fetter(dot)org>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>, PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Numeric overflow problem + patch
Date: 2006-09-28 21:11:43
Message-ID: 5577.1159477903@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

David Fetter <david(at)fetter(dot)org> writes:
> ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1.
> [ becomes ]
> ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1 - 5 * 10^-5.

This strikes me as overly pedantic. The message needs to be clear,
and the proposed change will just confuse people.

regards, tom lane


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: David Fetter <david(at)fetter(dot)org>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>, PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Numeric overflow problem + patch
Date: 2006-09-28 21:16:56
Message-ID: 20060928211656.GE16473@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Thu, Sep 28, 2006 at 05:11:43PM -0400, Tom Lane wrote:
> David Fetter <david(at)fetter(dot)org> writes:
> > ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1.
> > [ becomes ]
> > ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1 - 5 * 10^-5.
>
> This strikes me as overly pedantic. The message needs to be clear,
> and the proposed change will just confuse people.

I don't know if the code can detect the difference, but a message like:

A field with precision 4, scale 4 must *round to* an absolute value less than 1

Since that more accurately describes the actual problem.

Have a ncie day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.


From: David Fetter <david(at)fetter(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>, PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Numeric overflow problem + patch
Date: 2006-09-28 21:19:10
Message-ID: 20060928211910.GI22129@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Thu, Sep 28, 2006 at 05:11:43PM -0400, Tom Lane wrote:
> David Fetter <david(at)fetter(dot)org> writes:
> > ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1.
> > [ becomes ]
> > ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1 - 5 * 10^-5.
>
> This strikes me as overly pedantic. The message needs to be clear,
> and the proposed change will just confuse people.

It might, but the error that's currently in there is wrong. With the
patch applied, you get:

postgres=# SELECT .99995::NUMERIC(4,4);
ERROR: numeric field overflow
DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1 - 5 * 10^-5.

postgres=# SELECT .9999499999999999999999999999::NUMERIC(4,4);
numeric
---------
0.9999
(1 row)

I'd thought of changing it to the corresponding numeric piece, but
this doesn't work so well for NUMERIC(16,8) and the like.

Cheers,
D
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!


From: David Fetter <david(at)fetter(dot)org>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>, PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Numeric overflow problem + patch
Date: 2006-09-28 21:21:19
Message-ID: 20060928212118.GJ22129@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Thu, Sep 28, 2006 at 11:16:56PM +0200, Martijn van Oosterhout wrote:
> On Thu, Sep 28, 2006 at 05:11:43PM -0400, Tom Lane wrote:
> > David Fetter <david(at)fetter(dot)org> writes:
> > > ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1.
> > > [ becomes ]
> > > ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1 - 5 * 10^-5.
> >
> > This strikes me as overly pedantic. The message needs to be
> > clear, and the proposed change will just confuse people.
>
> I don't know if the code can detect the difference, but a message
> like:
>
> A field with precision 4, scale 4 must *round to* an absolute value
> less than 1

What does .999 round to? How about .5?

> Since that more accurately describes the actual problem.

I'd say it doesn't, as worded. Maybe some other wording would be
clearer.

Cheers,
D
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!


From: David Fetter <david(at)fetter(dot)org>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>, PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Numeric overflow problem + patch
Date: 2006-10-02 00:46:02
Message-ID: 20061002004602.GA18936@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Thu, Sep 28, 2006 at 11:16:56PM +0200, Martijn van Oosterhout wrote:
> On Thu, Sep 28, 2006 at 05:11:43PM -0400, Tom Lane wrote:
> > David Fetter <david(at)fetter(dot)org> writes:
> > > ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1.
> > > [ becomes ]
> > > ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1 - 5 * 10^-5.
> >
> > This strikes me as overly pedantic. The message needs to be clear,
> > and the proposed change will just confuse people.
>
> I don't know if the code can detect the difference, but a message like:
>
> A field with precision 4, scale 4 must *round to* an absolute value less than 1
>
> Since that more accurately describes the actual problem.
>
> Have a ncie day,

Per your suggestion, how about this patch?

Cheers,
D
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!

Attachment Content-Type Size
correct_numeric_overflow_error.patch text/plain 3.0 KB

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: David Fetter <david(at)fetter(dot)org>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>, PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Numeric overflow problem + patch
Date: 2006-10-03 21:25:58
Message-ID: 200610032125.k93LPwP07915@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Patch applied. Thanks.

---------------------------------------------------------------------------

David Fetter wrote:
> On Thu, Sep 28, 2006 at 11:16:56PM +0200, Martijn van Oosterhout wrote:
> > On Thu, Sep 28, 2006 at 05:11:43PM -0400, Tom Lane wrote:
> > > David Fetter <david(at)fetter(dot)org> writes:
> > > > ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1.
> > > > [ becomes ]
> > > > ! DETAIL: A field with precision 4, scale 4 must have an absolute value less than 1 - 5 * 10^-5.
> > >
> > > This strikes me as overly pedantic. The message needs to be clear,
> > > and the proposed change will just confuse people.
> >
> > I don't know if the code can detect the difference, but a message like:
> >
> > A field with precision 4, scale 4 must *round to* an absolute value less than 1
> >
> > Since that more accurately describes the actual problem.
> >
> > Have a ncie day,
>
> Per your suggestion, how about this patch?
>
> Cheers,
> D
> --
> David Fetter <david(at)fetter(dot)org> http://fetter.org/
> phone: +1 415 235 3778 AIM: dfetter666
> Skype: davidfetter
>
> Remember to vote!

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +