官方文档:http://www.postgresql.org/docs/8.1/static/plpgsql-errors-and-messages.html
Use the statement to report messages and raise errors.
RAISE '' [, [, ...]];
Possible levels are , , , , , and . raises an error (which normally aborts the current transaction); the other levels only generate messages of different priority levels. Whether messages of a particular priority are reported to the client, written to the server log, or both is controlled by the log_min_messages and client_min_messages configuration variables. See Chapter 17 for more information.
Inside the format string, is replaced by the next optional argument's string representation. Write to emit a literal . Arguments can be simple variables or expressions, and the format must be a simple string literal.
In this example, the value of will replace the in the string:
RAISE NOTICE 'Calling cs_create_job(%)', v_job_id;
This example will abort the transaction with the given error message:
RAISE EXCEPTION 'Nonexistent ID --> %', user_id;
presently always generates the same SQLSTATE code, , no matter what message it is invoked with. It is possible to trap this exception with but there is no way to tell one from another.