Re: Division by zero

Поиск
Список
Период
Сортировка
От Oliver Kohll - Mailing Lists
Тема Re: Division by zero
Дата
Msg-id 723BFE08-F740-4C3E-9585-148030F38FA0@gtwm.co.uk
обсуждение исходный текст
Ответ на Division by zero  (Oliver Kohll - Mailing Lists <oliver.lists@gtwm.co.uk>)
Список pgsql-general
On 4 Jun 2009, at 13:11, Sam Mason <sam@samason.me.uk> wrote:


You need to take care of only one case here: denominator == 0; rest of the
cases will be handled sanely by the database.

CASE WHEN packet_size = 0 THEN null ELSE cost/packet_size END as unit_cost

Yes; or even shorter:

 cost/nullif(packet_size,0) AS unit_cost

Thanks Sam and others. nullif is a good one to remember. However my problem is I want to be able to deal with an arbitrary calculation a user may create. In the light of a new day I realise this is obviously not trivial and would entail reasonably complex parsing. You'd have to find elements that could cause an error (division, some aggregates) and insert in the correct place nullif or CASE, taking care of bracket matching for starters - a messy workaround to the problem.

I might look into functions if that's the only reasonable way of catching exceptions.

Oliver

В списке pgsql-general по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Using a multi-valued function in a view
Следующее
От: Niklas Johansson
Дата:
Сообщение: Re: limit table to one row