PostgresError
struct PostgresErrorA PostgreSQL error, decomposed the way PQresultErrorField reports it: severity, SQLSTATE, primary message, and the optional detail/hint the server adds to explain or suggest a fix.
All fields are String and empty when the server didn't supply them.
sql is not one of libpq's fields — it's the statement text the caller
was executing, attached here so the formatted error is self-contained
in a log line.
Implements Copyable, Movable, Writable
- Fields
severity: String:ERROR,FATAL,PANIC, or a localized equivalent. Empty if unknown.sqlstate: String: The five-character SQLSTATE code, e.g.23505. Empty if the source of this error didn't have one (see the module docstring).message: String: The primary human-readable message.detail: String: An optional secondary message with more detail. Empty if absent.hint: String: An optional suggestion of how to fix the problem. Empty if absent.sql: String: The SQL text being executed when the error occurred. Empty if not attached.
__init__
def __init__(out self, severity: String = "", sqlstate: String = "", message: String = "", detail: String = "", hint: String = "", sql: String = "") format
def format(self) -> String Render the multi-line form this type prints and raises as.
Line one is "postgres [SQLSTATE 23505] <message>", or
"postgres: <message>" when there's no SQLSTATE to report. A
DETAIL: line follows if detail is set, then a HINT: line if
hint is set, then a SQL: line — collapsed to one line and
capped at 200 characters — if sql is set.
__str__
def __str__(self) -> String Same as format().
write_to
def write_to(self, mut writer: T) Write format() to writer — what makes String(err) and print(err) produce the formatted form.
to_error
def to_error(self) -> Error Wrap format() in an Error, ready to raise.
sqlstate_of() recovers self.sqlstate back out of the raised
Error on the far side of a try/except.
is_unique_violation
def is_unique_violation(self) -> Bool See the free function of the same name.
is_serialization_failure
def is_serialization_failure(self) -> Bool See the free function of the same name.
is_deadlock
def is_deadlock(self) -> Bool See the free function of the same name.
is_integrity_violation
def is_integrity_violation(self) -> Bool See the free function of the same name.
is_connection_error
def is_connection_error(self) -> Bool See the free function of the same name.
is_retryable
def is_retryable(self) -> Bool See the free function of the same name.