Catching errors in pl/pgsql

Поиск
Список
Период
Сортировка
От Fernando Papa
Тема Catching errors in pl/pgsql
Дата
Msg-id CB94A4924490EC4A81EDA55BA378B7BAE6F129@exch2k01.buehuergo.corp.claxson.com
обсуждение исходный текст
Ответы Re: Catching errors in pl/pgsql  (Richard Huxton <dev@archonet.com>)
Список pgsql-general
Hi everybody!

I'm migrating severals application from Oracle to PostgreSQL. I read all
the documents about PL/PGSQL and how porting from oracle to pg. I ported
several procedures succesful, but I have a lot of problems "translating"
this kind of code:
(...)
   EXCEPTION
      WHEN DUP_VAL_ON_INDEX THEN
         V_Error := 'PR_INSERT_VIOLATION_PK';
      WHEN E_Parent_Not_Found THEN
         V_Error := 'PR_INSERT_PARENT_NOT_FOUND';
      WHEN OTHERS THEN
         V_Error := 'PR_INSERT_OTHERS';
(...)

   IF vError IS NULL THEN
      COMMIT;
   ELSE
      ROLLBACK;
      RAISE_APPLICATION_ERROR(-20000,V_Error);
   ENDIF;
(...)

How I can catch the error, for example, if I try to insert a duplicate
value on primary key? or if parent keys not found? I need to catch the
error inside the pl/pgsql function and then pass a message to
application. I will rise a exception (I know how to do this) but I don't
know how to identify the errors...

Thanks in advance!

--
Fernando O. Papa
DBA

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

Предыдущее
От: Eric Audet
Дата:
Сообщение: No aswer WAS: Droping a database even if someone is con nected
Следующее
От: Olleg Samojlov
Дата:
Сообщение: Trigger in system catalog