Обсуждение: a math function with error handling

Поиск
Список
Период
Сортировка

a math function with error handling

От
Arthur Molina
Дата:
Hi there,

   I am new in this group and I've been working a lot in this function
but it didnt work good enought until now. Here is the thing: I use some
sql strings that calcultes a coll with another and I get the results.
For exemple I have two tables that has many float, texts or numeric colls.

Like Tab01 with V01 as varchar(10), V02 as numeric, V03 as float; and
Tab02 with F01 as varchar(20), F02 as float, F03 as float, F04 as
numeric. In the colls of varchar there will be times that there is a
number and others not.

There will be times that I will need to do a sum or division or any
other math. Just like this:
SELECT Tab01.V01 + Tab02.F03 FROM Tab01, Tab02
SELECT Tab01.V02 / Tab02.F01 FROM Tab01, Tab02

Well here is the thing, I get some errors by doing this because we can
have any results. So I need a function that tests this like:
evalthis(Tab01.V02 / Tab02.F01);

If I send something like 25 / '5' I get the result, 5
but if I send 25 / '0' I get null (division_by_zero)
or when I send 25 / 'textcrap' I get null too....

Is there any chance to get something like this?
sorry for my bad English

regards,
Arthur


_______________________________________________________
Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho agora!
http://br.mobile.yahoo.com/mailalertas/



Re: a math function with error handling

От
Chris Mair
Дата:
> If I send something like 25 / '5' I get the result, 5
> but if I send 25 / '0' I get null (division_by_zero)
> or when I send 25 / 'textcrap' I get null too....

You might want to look at pl/pgsql exception handlers:
http://www.postgresql.org/docs/8.1/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

Trapping division by zero is given as an example there...


Bye, Chris.


--

Chris Mair
http://www.1006.org