postgre SQL : 예외처리

2012. 11. 21. 18:25DataBase/Postgresql

반응형


예외처리? 오류처리?

음..anyways...찾아보니 RAISE 라는 것과 Exception이라는 것이 있는 것 같다.
우선 EXCEPTION 을 학습하고 적용시켜 보자^-^


http://www.postgresql.org/docs/8.0/static/plpgsql-control-structures.html


By default, any error occurring in a PL/pgSQL function aborts execution of the function, and indeed of the surrounding transaction as well. You can trap errors and recover from them by using a BEGIN block with an EXCEPTION clause. The syntax is an extension of the normal syntax for a BEGIN block:

[ <<label>> ]
[ DECLARE
    declarations ]
BEGIN
    statements
EXCEPTION
    WHEN condition [ OR condition ... ] THEN
        handler_statements
    [ WHEN condition [ OR condition ... ] THEN
          handler_statements
      ... ]
END;

예제 1] When an error is caught by an EXCEPTION clause, the local variables of the PL/pgSQL function remain as they were when the error occurred, but all changes to persistent database state within the block are rolled back. As an example, consider this fragment:

 
예제2] This example uses exception handling to perform either UPDATE or INSERT, as appropriate.
 

Handling Errors and Exceptions
RAISE statements raise errors and exceptions during a PL/pgSQL function's operation. A RAISE statement sends specified information to the PostgreSQL elog mechanism (the standard PostgreSQL error logging utility, which typically logs data either to /var/log/messages , or to $PGDATA/serverlog , as well as displaying to stderr ).

A RAISE statement is also given the level of error it should raise, and the string it should send to PostgreSQL. Additionally, you can list variables and expressions whose values you wish to have placed into the string. Use percent signs (%) to mark the locations in the string at which you want those values inserted. The syntax of the RAISE statement is as follows:

Table 11-1 lists the three possible values for the RAISE statement's level and their meanings.

http://www.linuxtopia.org/online_books/database_guides/Practical_PostgreSQL_database/PostgreSQL_x20238_003.htm

에러코드
http://www.postgresql.org/docs/9.1/static/errcodes-appendix.html

우선..더 학습이 필요할 것 같다..ㅋㅋ
퇴근 시간이니.. 집으로 =3=3=3;;
눈이 너무 피로하다..ㅠ_ㅠ.. 
반응형