Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are category codes in PostgreSQL?

Tags:

sql

postgresql

Regarding Error messeges, postgresql manual says:

Note: When specifying an error code by SQLSTATE code, you are not limited to the predefined error codes, but can select any error code consisting of five digits and/or upper-case ASCII letters, other than 00000. It is recommended that you avoid throwing error codes that end in three zeroes, because these are category codes and can only be trapped by trapping the whole category.

What are these category codes? In what case they are good use?

like image 660
java Avatar asked Dec 22 '25 03:12

java


1 Answers

Here is the list of error codes: Appendix A. PostgreSQL Error Codes

Error codes can be used for exception handling. And category codes are useful when you don't really care which exactly exception had been thrown as long as it is belong to a category. For example:

$$
BEGIN
   ...
EXCEPTION WHEN integrity_constraint_violation THEN
   ...
END
$$

In this case you will catch all exceptions that belong to integrity_constraint_violation category: foreign_key_violation, check_violation, etc.

like image 64
Ildar Musin Avatar answered Dec 23 '25 22:12

Ildar Musin