Re: division by zero issue

From: Jean-Luc Lachance <jllachan(at)sympatico(dot)ca>
To: Greg Donald <destiney(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: division by zero issue
Date: 2004-09-15 16:55:24
Message-ID: 414873FC.6060302@sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Add :

AND count(user_tasks.task_id) > 0 in the where clause.

Greg Donald wrote:

> Converting some MySQL code to work with Postgres here.
>
> I have this query:
>
> SELECT
> tasks.task_id,
> (tasks.task_duration * tasks.task_duration_type /
> count(user_tasks.task_id)) as hours_allocated
> FROM tasks
> LEFT JOIN user_tasks
> ON tasks.task_id = user_tasks.task_id
> WHERE tasks.task_milestone = '0'
> GROUP BY
> tasks.task_id,
> task_duration,
> task_duration_type
> ;
>
> The problem is that sometimes count(user_tasks.task_id) equals zero,
> so I get the division by zero error. Is there a simple way to make
> that part of the query fail silently and just equal zero instead of
> dividing and producing the error?
>
> TIA..
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guy Fraser 2004-09-15 17:01:45 Re: division by zero issue
Previous Message Tom Lane 2004-09-15 16:51:40 Re: Problems with SPI memory management