Skip to main content

SQL errors

The PostgreSQL front end returns standard SQLSTATE codes where the behaviour maps cleanly, and documents the boundaries where it does not.

Codes​

SQLSTATENameTypical cause
0A000feature_not_supportedDELETE, COPY ... TO STDOUT, CREATE TABLE AS, TRUNCATE, non-READ COMMITTED isolation, unsupported DDL clause
21000cardinality_violationA scalar subquery returned more than one row
22007invalid_datetime_formatA timestamp or date literal could not be parsed
22023invalid_parameter_valueInvalid SET value or table option
22P02invalid_text_representationA string literal does not convert to the target type
23505unique_violationDuplicate primary key on a plain insert
25P02in_failed_sql_transactionA statement after a failed transaction, until ROLLBACK
40001serialization_failureLost a write race; retry the statement
42601syntax_errorSQL syntax error, or source/target column mismatch
42701duplicate_columnA column is declared twice, including in PARTITIONED BY
42703undefined_columnUnknown column
42804datatype_mismatchAn expression is not assignment-castable
42P01undefined_tableUnknown table
42P07duplicate_tableTable already exists
42P16invalid_table_definitionInvalid primary key or table definition
3F000invalid_schema_nameInvalid schema in a qualified name
57014query_canceledstatement_timeout or a cancel request
XX000internal_errorEngine error, or an unknown database at startup

Mapping boundaries​

These are documented rather than silently different:

CaseLakeSoulPostgreSQL
Invalid integer conversionXX00022P02
Unknown database at startupFATAL XX000Different message and code
rank() / row_number() typeNUMERICINT8
COALESCE(integer_col, -1) typeINT8INT4

Match on the SQLSTATE where the table above says it matches; parse the message only as a fallback.

Retrying​

  • 40001 is retryable: the statement lost a race with a concurrent writer. Retry it once the other transaction has committed.
  • 23505 is not retryable as-is: the key already exists. Use ON CONFLICT if an upsert is intended.
  • 57014 is a cancellation, not a data error; the connection remains usable.

Next​