Re: Division by zero - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Division by zero
Date
Msg-id 20050416090510.GA35437@winnie.fuhr.org
Whole thread Raw
In response to Division by zero  (Costin Manda <siderite@madnet.ro>)
List pgsql-general
On Sat, Apr 16, 2005 at 10:15:55AM +0300, Costin Manda wrote:
>
> In other SQL programs a division by zero is solved by transforming the
> result to NULL.

The SQL standards state that "If the value of a divisor is zero,
then an exception condition is raised: data exception -- division
by zero."  Databases that silently convert this exception to NULL
(e.g., MySQL) are violating standards.

> How can I make postgres have the same behaviour without using CASE ?

Why don't you want to use CASE?  Because it's unwieldy?

You could wrap CASE in a function and call that function instead
of using the / operator.  I'd avoid any temptation to change the
behavior of the operator itself because that could cause problems
in other code that isn't expecting it.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: Poul Møller Hansen
Date:
Subject: Re: Loosing connection with the database
Next
From: "Craig Bryden"
Date:
Subject: Re: Division by zero