Re: Division by zero

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Costin Manda <siderite(at)madnet(dot)ro>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Division by zero
Date: 2005-04-16 09:05:11
Message-ID: 20050416090510.GA35437@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Bryden 2005-04-16 11:14:37 Re: Division by zero
Previous Message Poul Møller Hansen 2005-04-16 08:37:16 Re: Loosing connection with the database