Обсуждение: how can I check the error status??

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

how can I check the error status??

От
"Luis Alberto Pérez Paz"
Дата:
Hi everybody!
 
I'm migrating some sybase store procedures to postgres functions,
I almost have found all that I need, however I dont know how to check the error status of the last transaction.
I need to find in postgres the equivalent to the sybase @@error global variable.
 
I mean, how can I translate this code in a postgres function?:
 
insert into table (a,b,c) values (1,2,3)
 if (@@error =0)
  return 0
 else
  return -900
 
 
Any advices?
 
thanks in advance!
 
Luis Paz.


--
paz, amor y comprensión
        (1967-1994)

Re: how can I check the error status??

От
Richard Huxton
Дата:
Luis Alberto Pérez Paz wrote:
> Hi everybody!
>
> I'm migrating some sybase store procedures to postgres functions,
> I almost have found all that I need, however I dont know how to check the
> error status of the last transaction.
> I need to find in postgres the equivalent to the sybase @@error global
> variable.

If you're using pl/pgsql then you'll want to read the "Trapping Errors"
chapter of the manuals.

http://www.postgresql.org/docs/8.1/static/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING

--
   Richard Huxton
   Archonet Ltd