Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sql.postgres.errors

import sql.postgres.errors

sql lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled sql.postgres.errors.* needs import sql.postgres.errors.

Turning PostgreSQL’s SQLSTATE codes into the shared error classes.

Every error PostgreSQL reports carries a five character SQLSTATE. The first two characters are its class and the rest narrow it down, so 23505 is class 23, integrity constraint violation, specifically a unique violation. Mapping works on the specific code where one is worth telling apart and falls back to the class otherwise, which means a code this table has never seen still lands somewhere sensible.

Constants

SPECIFIC

sql.postgres.errors.SPECIFIC = {...}

Codes specific enough to name a class of their own.

CLASSES

sql.postgres.errors.CLASSES = {...}

SQLSTATE classes, for codes the table above does not name.

Functions

class_for()

sql.postgres.class_for(sqlstate) -> class

The class that best describes sqlstate.

Parameters

  • sqlstate (string|nil)

Returns class

raise_for()

sql.postgres.raise_for(report: dict, query)

Raises the right class for a server error report.

Parameters

  • report (dict) — The fields the server sent, as protocol.parse_error() returns them.
  • query (string|nil) — The statement that was running.

Raises SqlError always.


2026, Richard Ore and Zuri contributors