Re: division by zero issue - Mailing list pgsql-general

From Magnus Hagander
Subject Re: division by zero issue
Date
Msg-id 6BCB9D8A16AC4241919521715F4D8BCE475CAA@algol.sollentuna.se
Whole thread Raw
In response to division by zero issue  (Greg Donald <destiney@gmail.com>)
List pgsql-general
> Thanks, you guys are so helpful.
>
> This works great on my workstation with 7.4.5.  But what's
> the 7.2 way of doing it?  Our production server is a bit older.
>
> I also tried Mr Fraser's suggestion:
>
> SELECT
>   tasks.task_id,
>   CASE
>     WHEN task_count = '0'
>     THEN '0'::int4
>     ELSE (task_duration * task_duration_type / task_count) as
> hours_allocated
>   END
> FROM
> (
>   SELECT
>   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
> ) as intermediate;
>
> but it's producing an error near the AS for some reason I can't tell.
> I tried wrapping it with some parentheses but it didn't help.

You're missing an END:

> SELECT
>   tasks.task_id,
>   CASE
>     WHEN task_count = '0'
>     THEN '0'::int4
>     ELSE (task_duration * task_duration_type / task_count) END as
                                                           ^^^^^^^

> hours_allocated
>   END
> FROM
...


//Magnus

pgsql-general by date:

Previous
From: "Matthew T. O'Connor"
Date:
Subject: Re: Corrupted Data?
Next
From: David Fetter
Date:
Subject: Re: division by zero issue