postgre SQL : 예외처리

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


예외처리? 오류처리?

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

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>> ]
    declarations ]
    WHEN condition [ OR condition ... ] THEN
    [ WHEN condition [ OR condition ... ] THEN
      ... ]

예제 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.


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