Re: Infinity vs Error for division by zero

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Matt Pulver <mpulver(at)unitytechgroup(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Infinity vs Error for division by zero
Date: 2019-03-01 18:04:04
Message-ID: CAKFQuwav8Sr++0RjugrrKC3SWqZ_AXdO+9kxh_0kC9ouXsnpwg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Friday, March 1, 2019, Matt Pulver <mpulver(at)unitytechgroup(dot)com> wrote:

> However the query "SELECT 1.0/0.0;" produces an exception:
>
> ERROR: division by zero
>
>
> Question: If Infinity and NaN are supported, then why throw an exception
> here, instead of returning Infinity? Is it purely for historical reasons,
> or if it could all be done again, would an exception still be preferred?
>
> For purely integer arithmetic, I can see how an exception would make
> sense. However for FLOAT, I would expect/prefer Infinity to be returned.
>

1/0 is an illegal operation. We could return NaN for it but the choice of
throwing an error is just as correct. Returning infinity is strictly
incorrect.

Changing the behavior is not going to happen for any existing data types.

David J.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2019-03-01 18:04:38 Re: Infinity vs Error for division by zero
Previous Message Andrew Gierth 2019-03-01 17:59:42 Re: Infinity vs Error for division by zero