---
id: "sqlstate"
kind: "datatype"
status: "draft"
is_pii: false
categories: ["software"]
langs: ["common"]
quality: 80
url: "https://registry.apicrafter.io/datatype/sqlstate"
---

# SQLSTATE code (`sqlstate`)

> **Draft.** Draft records have not been reviewed yet and may be incomplete or wrong; do not treat them as authoritative for legal or compliance decisions.

Five-character code with which a SQL database reports the result of a statement, defined by the SQL standard. The first two characters are the class of the condition and the last three are the condition in that class. A code that ends in 000 is the generic code of its class. Codes use digits and capital letters. PostgreSQL, Db2, Oracle and ODBC and JDBC drivers return them, and database logs store them.

- Personal data (PII): no
- Categories: Software development (software)
- Countries: global
- Languages: Common to most languages (common)
- Classification: categorical

## Detection

Regular expression (Python `re`):

```
^[0-9A-Z]{5}$
```

## Examples

- `42601` — syntax_error in PostgreSQL
- `23505` — unique_violation in PostgreSQL
- `42P01` — undefined_table in PostgreSQL
- `40P01` — deadlock_detected in PostgreSQL
- `42p01` (invalid example) — Lowercase letter

## Translations

- ru: Код SQLSTATE

## Sources

- doc: <https://www.postgresql.org/docs/current/errcodes-appendix.html>

## Quality

Score 80/100. Missing: mapping (Wikidata, Schema.org, ...), detector coverage.

JSON: <https://registry.apicrafter.io/api/v1/datatypes/sqlstate.json> · Edit: <https://github.com/apicrafter/metacrafter-registry/edit/main/data/datatypes/any/software/sqlstate.yaml>
