1
`psycopg2.errorcodes` -- Error codes defined by PostgreSQL
2
===============================================================
4
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
9
.. module:: psycopg2.errorcodes
13
from psycopg2 import errorcodes
15
.. versionadded:: 2.0.6
17
This module contains symbolic names for all PostgreSQL error codes and error
18
classes codes. Subclasses of `~psycopg2.Error` make the PostgreSQL error
19
code available in the `~psycopg2.Error.pgcode` attribute.
21
From PostgreSQL documentation:
23
All messages emitted by the PostgreSQL server are assigned five-character
24
error codes that follow the SQL standard's conventions for :sql:`SQLSTATE`
25
codes. Applications that need to know which error condition has occurred
26
should usually test the error code, rather than looking at the textual
27
error message. The error codes are less likely to change across
28
PostgreSQL releases, and also are not subject to change due to
29
localization of error messages. Note that some, but not all, of the error
30
codes produced by PostgreSQL are defined by the SQL standard; some
31
additional error codes for conditions not defined by the standard have
32
been invented or borrowed from other databases.
34
According to the standard, the first two characters of an error code
35
denote a class of errors, while the last three characters indicate a
36
specific condition within that class. Thus, an application that does not
37
recognize the specific error code can still be able to infer what to do
40
.. seealso:: `PostgreSQL Error Codes table`__
42
.. __: http://www.postgresql.org/docs/8.4/static/errcodes-appendix.html#ERRCODES-TABLE
45
An example of the available constants defined in the module:
47
>>> errorcodes.CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION
49
>>> errorcodes.UNDEFINED_TABLE
52
Constants representing all the error values documented by PostgreSQL versions
53
between 8.1 and 8.4 are included in the module.
56
.. autofunction:: lookup(code)
61
... cur.execute("SELECT ouch FROM aargh;")
62
... except Exception, e:
65
>>> errorcodes.lookup(e.pgcode[:2])
66
'CLASS_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION'
67
>>> errorcodes.lookup(e.pgcode)
70
.. versionadded:: 2.0.14