Re: Trapping errors

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: Trapping errors
Дата
Msg-id 406C459E-1D85-41AD-807A-E4C2E85A5516@solfertje.student.utwente.nl
обсуждение исходный текст
Ответ на Trapping errors  (Shane W <shane-pgsql@csy.ca>)
Список pgsql-general
On 23 May 2011, at 22:08, Shane W wrote:

> Hello list,
>
> I have a table with double precision columns and update
> queries which multiply and divide these values. I am
> wondering if it's possible to catch overflow and underflow
> errors to set the column to 0 in the case of an underflow
> and a large value in the case of an overflow.
>
> Currently, I have an exception handler in a PLPGSQL
> ufunction that sort of does this.
>
> begin
> update tbl set score = score/s
> exception when numeric_value_out_of range then
> update tbl set score=0
> where cast(score/s as numeric) < 1e-200
> end;
>
> But this is messy since the exception needs to rescan the
> entire table if even one row fails the update. Is there a
> better way to do this?


If you move the overflow/underflow check into a before-trigger, then you can use the NEW.* and OLD.* variables to alter
therow before it gets written. That way you scan the table only once and you also moved your handling of such errors
intothe database (which means that if other applications than your client ever write values to that table, the same
rulesare applied). 

Alban Hertroys

--
Screwing up is an excellent way to attach something to the ceiling.


!DSPAM:737,4ddb6e8111921119526771!



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

Предыдущее
От: Adrian Schreyer
Дата:
Сообщение: Dumping schemas using pg_dump without extensions (9.1 Beta)
Следующее
От: Alban Hertroys
Дата:
Сообщение: Re: strange behaviour in 9.0.2 / ERROR: 22003: value out of range: overflow