$57 GRAYBYTE WORDPRESS FILE MANAGER $11

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python37/share/doc/alt-python37-psycopg2/doc/src/

HOME
Current File : /opt/alt/python37/share/doc/alt-python37-psycopg2/doc/src//errors.rst
`psycopg2.errors` -- Exception classes mapping PostgreSQL errors
================================================================

.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>

.. index::
    single: Error; Class

.. module:: psycopg2.errors

.. versionadded:: 2.8

.. versionchanged:: 2.8.4 added errors introduced in PostgreSQL 12

This module exposes the classes psycopg raises upon receiving an error from
the database with a :sql:`SQLSTATE` value attached (available in the
`~psycopg2.Error.pgcode` attribute). The content of the module is generated
from the PostgreSQL source code and includes classes for every error defined
by PostgreSQL in versions between 9.1 and 12.

Every class in the module is named after what referred as "condition name" `in
the documentation`__, converted to CamelCase: e.g. the error 22012,
``division_by_zero`` is exposed by this module as the class `!DivisionByZero`.

.. __: https://www.postgresql.org/docs/current/static/errcodes-appendix.html#ERRCODES-TABLE

Every exception class is a subclass of one of the :ref:`standard DB-API
exception <dbapi-exceptions>` and expose the `~psycopg2.Error` interface.
Each class' superclass is what used to be raised by psycopg in versions before
the introduction of this module, so everything should be compatible with
previously written code catching one the DB-API class: if your code used to
catch `!IntegrityError` to detect a duplicate entry, it will keep on working
even if a more specialised subclass such as `UniqueViolation` is raised.

The new classes allow a more idiomatic way to check and process a specific
error among the many the database may return. For instance, in order to check
that a table is locked, the following code could have been used previously:

.. code-block:: python

    try:
        cur.execute("LOCK TABLE mytable IN ACCESS EXCLUSIVE MODE NOWAIT")
    except psycopg2.OperationalError as e:
        if e.pgcode == psycopg2.errorcodes.LOCK_NOT_AVAILABLE:
            locked = True
        else:
            raise

While this method is still available, the specialised class allows for a more
idiomatic error handler:

.. code-block:: python

    try:
        cur.execute("LOCK TABLE mytable IN ACCESS EXCLUSIVE MODE NOWAIT")
    except psycopg2.errors.LockNotAvailable:
        locked = True


.. autofunction:: lookup

    .. code-block:: python

        try:
            cur.execute("LOCK TABLE mytable IN ACCESS EXCLUSIVE MODE NOWAIT")
        except psycopg2.errors.lookup("55P03"):
            locked = True


SQLSTATE exception classes
--------------------------

The following table contains the list of all the SQLSTATE classes exposed by
the module.

Note that, for completeness, the module also exposes all the
:ref:`DB-API-defined exceptions <dbapi-exceptions>` and :ref:`a few
psycopg-specific ones <extension-exceptions>` exposed by the `!extensions`
module, which are not listed here.

.. include:: sqlstate_errors.rst

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
31 Aug 2024 3.40 AM
root / root
0755
_static
--
31 Aug 2024 3.40 AM
root / root
0755
tools
--
31 Aug 2024 3.40 AM
root / root
0755
Makefile
3.309 KB
20 Oct 2019 7.45 AM
root / root
0644
advanced.rst
21.903 KB
20 Oct 2019 7.45 AM
root / root
0644
conf.py
8.267 KB
20 Oct 2019 7.45 AM
root / root
0644
connection.rst
33.257 KB
20 Oct 2019 7.45 AM
root / root
0644
cursor.rst
23.048 KB
20 Oct 2019 7.45 AM
root / root
0644
errorcodes.rst
2.455 KB
20 Oct 2019 7.45 AM
root / root
0644
errors.rst
2.896 KB
20 Oct 2019 7.45 AM
root / root
0644
extensions.rst
32.812 KB
20 Oct 2019 7.45 AM
root / root
0644
extras.rst
35.607 KB
20 Oct 2019 7.45 AM
root / root
0644
faq.rst
14.587 KB
20 Oct 2019 7.45 AM
root / root
0644
index.rst
1.833 KB
20 Oct 2019 7.45 AM
root / root
0644
install.rst
10.31 KB
20 Oct 2019 7.45 AM
root / root
0644
license.rst
0.074 KB
20 Oct 2019 7.45 AM
root / root
0644
module.rst
13.035 KB
20 Oct 2019 7.45 AM
root / root
0644
news.rst
0.105 KB
20 Oct 2019 7.45 AM
root / root
0644
pool.rst
1.822 KB
20 Oct 2019 7.45 AM
root / root
0644
sql.rst
3.021 KB
20 Oct 2019 7.45 AM
root / root
0644
tz.rst
0.529 KB
20 Oct 2019 7.45 AM
root / root
0644
usage.rst
40.679 KB
20 Oct 2019 7.45 AM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF