risingwave_error/
code.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use serde::{Deserialize, Serialize};
16
17/// Represents all possible PostgreSQL error codes as defined in Table A.1.
18///
19/// Each variant corresponds to a specific `Condition Name` from the PostgreSQL documentation.
20/// This enum provides a type-safe way to handle and match on specific SQLSTATE error codes.
21///
22/// See: <https://www.postgresql.org/docs/13/errcodes-appendix.html>.
23#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
24#[non_exhaustive]
25pub enum PostgresErrorCode {
26    // Class 00 — Successful Completion
27    /// **Code `00000`**: `successful_completion`
28    SuccessfulCompletion,
29
30    // Class 01 — Warning
31    /// **Code `01000`**: `warning`
32    Warning,
33    /// **Code `0100C`**: `dynamic_result_sets_returned`
34    DynamicResultSetsReturned,
35    /// **Code `01008`**: `implicit_zero_bit_padding`
36    ImplicitZeroBitPadding,
37    /// **Code `01003`**: `null_value_eliminated_in_set_function`
38    NullValueEliminatedInSetFunction,
39    /// **Code `01007`**: `privilege_not_granted`
40    PrivilegeNotGranted,
41    /// **Code `01006`**: `privilege_not_revoked`
42    PrivilegeNotRevoked,
43    /// **Code `01004`**: `string_data_right_truncation`
44    StringDataRightTruncation01004,
45    /// **Code `01P01`**: `deprecated_feature`
46    DeprecatedFeature,
47
48    // Class 02 — No Data
49    /// **Code `02000`**: `no_data`
50    NoData,
51    /// **Code `02001`**: `no_additional_dynamic_result_sets_returned`
52    NoAdditionalDynamicResultSetsReturned,
53
54    // Class 03 — SQL Statement Not Yet Complete
55    /// **Code `03000`**: `sql_statement_not_yet_complete`
56    SqlStatementNotYetComplete,
57
58    // Class 08 — Connection Exception
59    /// **Code `08000`**: `connection_exception`
60    ConnectionException,
61    /// **Code `08003`**: `connection_does_not_exist`
62    ConnectionDoesNotExist,
63    /// **Code `08006`**: `connection_failure`
64    ConnectionFailure,
65    /// **Code `08001`**: `sqlclient_unable_to_establish_sqlconnection`
66    SqlclientUnableToEstablishSqlconnection,
67    /// **Code `08004`**: `sqlserver_rejected_establishment_of_sqlconnection`
68    SqlserverRejectedEstablishmentOfSqlconnection,
69    /// **Code `08007`**: `transaction_resolution_unknown`
70    TransactionResolutionUnknown,
71    /// **Code `08P01`**: `protocol_violation`
72    ProtocolViolation,
73
74    // Class 09 — Triggered Action Exception
75    /// **Code `09000`**: `triggered_action_exception`
76    TriggeredActionException,
77
78    // Class 0A — Feature Not Supported
79    /// **Code `0A000`**: `feature_not_supported`
80    FeatureNotSupported,
81
82    // Class 0B — Invalid Transaction Initiation
83    /// **Code `0B000`**: `invalid_transaction_initiation`
84    InvalidTransactionInitiation,
85
86    // Class 0F — Locator Exception
87    /// **Code `0F000`**: `locator_exception`
88    LocatorException,
89    /// **Code `0F001`**: `invalid_locator_specification`
90    InvalidLocatorSpecification,
91
92    // Class 0L — Invalid Grantor
93    /// **Code `0L000`**: `invalid_grantor`
94    InvalidGrantor,
95    /// **Code `0LP01`**: `invalid_grant_operation`
96    InvalidGrantOperation,
97
98    // Class 0P — Invalid Role Specification
99    /// **Code `0P000`**: `invalid_role_specification`
100    InvalidRoleSpecification,
101
102    // Class 0Z — Diagnostics Exception
103    /// **Code `0Z000`**: `diagnostics_exception`
104    DiagnosticsException,
105    /// **Code `0Z002`**: `stacked_diagnostics_accessed_without_active_handler`
106    StackedDiagnosticsAccessedWithoutActiveHandler,
107
108    // Class 20 — Case Not Found
109    /// **Code `20000`**: `case_not_found`
110    CaseNotFound,
111
112    // Class 21 — Cardinality Violation
113    /// **Code `21000`**: `cardinality_violation`
114    CardinalityViolation,
115
116    // Class 22 — Data Exception
117    /// **Code `22000`**: `data_exception`
118    DataException,
119    /// **Code `2202E`**: `array_subscript_error`
120    ArraySubscriptError,
121    /// **Code `22021`**: `character_not_in_repertoire`
122    CharacterNotInRepertoire,
123    /// **Code `22008`**: `datetime_field_overflow`
124    DatetimeFieldOverflow,
125    /// **Code `22012`**: `division_by_zero`
126    DivisionByZero,
127    /// **Code `22005`**: `error_in_assignment`
128    ErrorInAssignment,
129    /// **Code `2200B`**: `escape_character_conflict`
130    EscapeCharacterConflict,
131    /// **Code `22022`**: `indicator_overflow`
132    IndicatorOverflow,
133    /// **Code `22015`**: `interval_field_overflow`
134    IntervalFieldOverflow,
135    /// **Code `2201E`**: `invalid_argument_for_logarithm`
136    InvalidArgumentForLogarithm,
137    /// **Code `22014`**: `invalid_argument_for_ntile_function`
138    InvalidArgumentForNtileFunction,
139    /// **Code `22016`**: `invalid_argument_for_nth_value_function`
140    InvalidArgumentForNthValueFunction,
141    /// **Code `2201F`**: `invalid_argument_for_power_function`
142    InvalidArgumentForPowerFunction,
143    /// **Code `2201G`**: `invalid_argument_for_width_bucket_function`
144    InvalidArgumentForWidthBucketFunction,
145    /// **Code `22018`**: `invalid_character_value_for_cast`
146    InvalidCharacterValueForCast,
147    /// **Code `22007`**: `invalid_datetime_format`
148    InvalidDatetimeFormat,
149    /// **Code `22019`**: `invalid_escape_character`
150    InvalidEscapeCharacter,
151    /// **Code `2200D`**: `invalid_escape_octet`
152    InvalidEscapeOctet,
153    /// **Code `22025`**: `invalid_escape_sequence`
154    InvalidEscapeSequence,
155    /// **Code `22P06`**: `nonstandard_use_of_escape_character`
156    NonstandardUseOfEscapeCharacter,
157    /// **Code `22010`**: `invalid_indicator_parameter_value`
158    InvalidIndicatorParameterValue,
159    /// **Code `22023`**: `invalid_parameter_value`
160    InvalidParameterValue,
161    /// **Code `22013`**: `invalid_preceding_or_following_size`
162    InvalidPrecedingOrFollowingSize,
163    /// **Code `2201B`**: `invalid_regular_expression`
164    InvalidRegularExpression,
165    /// **Code `2201W`**: `invalid_row_count_in_limit_clause`
166    InvalidRowCountInLimitClause,
167    /// **Code `2201X`**: `invalid_row_count_in_result_offset_clause`
168    InvalidRowCountInResultOffsetClause,
169    /// **Code `2202H`**: `invalid_tablesample_argument`
170    InvalidTablesampleArgument,
171    /// **Code `2202G`**: `invalid_tablesample_repeat`
172    InvalidTablesampleRepeat,
173    /// **Code `22009`**: `invalid_time_zone_displacement_value`
174    InvalidTimeZoneDisplacementValue,
175    /// **Code `2200C`**: `invalid_use_of_escape_character`
176    InvalidUseOfEscapeCharacter,
177    /// **Code `2200G`**: `most_specific_type_mismatch`
178    MostSpecificTypeMismatch,
179    /// **Code `22004`**: `null_value_not_allowed`
180    NullValueNotAllowed22004,
181    /// **Code `22002`**: `null_value_no_indicator_parameter`
182    NullValueNoIndicatorParameter,
183    /// **Code `22003`**: `numeric_value_out_of_range`
184    NumericValueOutOfRange,
185    /// **Code `2200H`**: `sequence_generator_limit_exceeded`
186    SequenceGeneratorLimitExceeded,
187    /// **Code `22026`**: `string_data_length_mismatch`
188    StringDataLengthMismatch,
189    /// **Code `22001`**: `string_data_right_truncation`
190    StringDataRightTruncation22001,
191    /// **Code `22011`**: `substring_error`
192    SubstringError,
193    /// **Code `22027`**: `trim_error`
194    TrimError,
195    /// **Code `22024`**: `unterminated_c_string`
196    UnterminatedCString,
197    /// **Code `2200F`**: `zero_length_character_string`
198    ZeroLengthCharacterString,
199    /// **Code `22P01`**: `floating_point_exception`
200    FloatingPointException,
201    /// **Code `22P02`**: `invalid_text_representation`
202    InvalidTextRepresentation,
203    /// **Code `22P03`**: `invalid_binary_representation`
204    InvalidBinaryRepresentation,
205    /// **Code `22P04`**: `bad_copy_file_format`
206    BadCopyFileFormat,
207    /// **Code `22P05`**: `untranslatable_character`
208    UntranslatableCharacter,
209    /// **Code `2200L`**: `not_an_xml_document`
210    NotAnXmlDocument,
211    /// **Code `2200M`**: `invalid_xml_document`
212    InvalidXmlDocument,
213    /// **Code `2200N`**: `invalid_xml_content`
214    InvalidXmlContent,
215    /// **Code `2200S`**: `invalid_xml_comment`
216    InvalidXmlComment,
217    /// **Code `2200T`**: `invalid_xml_processing_instruction`
218    InvalidXmlProcessingInstruction,
219    /// **Code `22030`**: `duplicate_json_object_key_value`
220    DuplicateJsonObjectKeyValue,
221    /// **Code `22031`**: `invalid_argument_for_sql_json_datetime_function`
222    InvalidArgumentForSqlJsonDatetimeFunction,
223    /// **Code `22032`**: `invalid_json_text`
224    InvalidJsonText,
225    /// **Code `22033`**: `invalid_sql_json_subscript`
226    InvalidSqlJsonSubscript,
227    /// **Code `22034`**: `more_than_one_sql_json_item`
228    MoreThanOneSqlJsonItem,
229    /// **Code `22035`**: `no_sql_json_item`
230    NoSqlJsonItem,
231    /// **Code `22036`**: `non_numeric_sql_json_item`
232    NonNumericSqlJsonItem,
233    /// **Code `22037`**: `non_unique_keys_in_a_json_object`
234    NonUniqueKeysInAJsonObject,
235    /// **Code `22038`**: `singleton_sql_json_item_required`
236    SingletonSqlJsonItemRequired,
237    /// **Code `22039`**: `sql_json_array_not_found`
238    SqlJsonArrayNotFound,
239    /// **Code `2203A`**: `sql_json_member_not_found`
240    SqlJsonMemberNotFound,
241    /// **Code `2203B`**: `sql_json_number_not_found`
242    SqlJsonNumberNotFound,
243    /// **Code `2203C`**: `sql_json_object_not_found`
244    SqlJsonObjectNotFound,
245    /// **Code `2203D`**: `too_many_json_array_elements`
246    TooManyJsonArrayElements,
247    /// **Code `2203E`**: `too_many_json_object_members`
248    TooManyJsonObjectMembers,
249    /// **Code `2203F`**: `sql_json_scalar_required`
250    SqlJsonScalarRequired,
251
252    // Class 23 — Integrity Constraint Violation
253    /// **Code `23000`**: `integrity_constraint_violation`
254    IntegrityConstraintViolation,
255    /// **Code `23001`**: `restrict_violation`
256    RestrictViolation,
257    /// **Code `23502`**: `not_null_violation`
258    NotNullViolation,
259    /// **Code `23503`**: `foreign_key_violation`
260    ForeignKeyViolation,
261    /// **Code `23505`**: `unique_violation`
262    UniqueViolation,
263    /// **Code `23514`**: `check_violation`
264    CheckViolation,
265    /// **Code `23P01`**: `exclusion_violation`
266    ExclusionViolation,
267
268    // Class 24 — Invalid Cursor State
269    /// **Code `24000`**: `invalid_cursor_state`
270    InvalidCursorState,
271
272    // Class 25 — Invalid Transaction State
273    /// **Code `25000`**: `invalid_transaction_state`
274    InvalidTransactionState,
275    /// **Code `25001`**: `active_sql_transaction`
276    ActiveSqlTransaction,
277    /// **Code `25002`**: `branch_transaction_already_active`
278    BranchTransactionAlreadyActive,
279    /// **Code `25008`**: `held_cursor_requires_same_isolation_level`
280    HeldCursorRequiresSameIsolationLevel,
281    /// **Code `25003`**: `inappropriate_access_mode_for_branch_transaction`
282    InappropriateAccessModeForBranchTransaction,
283    /// **Code `25004`**: `inappropriate_isolation_level_for_branch_transaction`
284    InappropriateIsolationLevelForBranchTransaction,
285    /// **Code `25005`**: `no_active_sql_transaction_for_branch_transaction`
286    NoActiveSqlTransactionForBranchTransaction,
287    /// **Code `25006`**: `read_only_sql_transaction`
288    ReadOnlySqlTransaction,
289    /// **Code `25007`**: `schema_and_data_statement_mixing_not_supported`
290    SchemaAndDataStatementMixingNotSupported,
291    /// **Code `25P01`**: `no_active_sql_transaction`
292    NoActiveSqlTransaction,
293    /// **Code `25P02`**: `in_failed_sql_transaction`
294    InFailedSqlTransaction,
295    /// **Code `25P03`**: `idle_in_transaction_session_timeout`
296    IdleInTransactionSessionTimeout,
297
298    // Class 26 — Invalid SQL Statement Name
299    /// **Code `26000`**: `invalid_sql_statement_name`
300    InvalidSqlStatementName,
301
302    // Class 27 — Triggered Data Change Violation
303    /// **Code `27000`**: `triggered_data_change_violation`
304    TriggeredDataChangeViolation,
305
306    // Class 28 — Invalid Authorization Specification
307    /// **Code `28000`**: `invalid_authorization_specification`
308    InvalidAuthorizationSpecification,
309    /// **Code `28P01`**: `invalid_password`
310    InvalidPassword,
311
312    // Class 2B — Dependent Privilege Descriptors Still Exist
313    /// **Code `2B000`**: `dependent_privilege_descriptors_still_exist`
314    DependentPrivilegeDescriptorsStillExist,
315    /// **Code `2BP01`**: `dependent_objects_still_exist`
316    DependentObjectsStillExist,
317
318    // Class 2D — Invalid Transaction Termination
319    /// **Code `2D000`**: `invalid_transaction_termination`
320    InvalidTransactionTermination,
321
322    // Class 2F — SQL Routine Exception
323    /// **Code `2F000`**: `sql_routine_exception`
324    SqlRoutineException,
325    /// **Code `2F005`**: `function_executed_no_return_statement`
326    FunctionExecutedNoReturnStatement,
327    /// **Code `2F002`**: `modifying_sql_data_not_permitted`
328    ModifyingSqlDataNotPermitted2F002,
329    /// **Code `2F003`**: `prohibited_sql_statement_attempted`
330    ProhibitedSqlStatementAttempted2F003,
331    /// **Code `2F004`**: `reading_sql_data_not_permitted`
332    ReadingSqlDataNotPermitted2F004,
333
334    // Class 34 — Invalid Cursor Name
335    /// **Code `34000`**: `invalid_cursor_name`
336    InvalidCursorName,
337
338    // Class 38 — External Routine Exception
339    /// **Code `38000`**: `external_routine_exception`
340    ExternalRoutineException,
341    /// **Code `38001`**: `containing_sql_not_permitted`
342    ContainingSqlNotPermitted,
343    /// **Code `38002`**: `modifying_sql_data_not_permitted`
344    ModifyingSqlDataNotPermitted38002,
345    /// **Code `38003`**: `prohibited_sql_statement_attempted`
346    ProhibitedSqlStatementAttempted38003,
347    /// **Code `38004`**: `reading_sql_data_not_permitted`
348    ReadingSqlDataNotPermitted38004,
349
350    // Class 39 — External Routine Invocation Exception
351    /// **Code `39000`**: `external_routine_invocation_exception`
352    ExternalRoutineInvocationException,
353    /// **Code `39001`**: `invalid_sqlstate_returned`
354    InvalidSqlstateReturned,
355    /// **Code `39004`**: `null_value_not_allowed`
356    NullValueNotAllowed39004,
357    /// **Code `39P01`**: `trigger_protocol_violated`
358    TriggerProtocolViolated,
359    /// **Code `39P02`**: `srf_protocol_violated`
360    SrfProtocolViolated,
361    /// **Code `39P03`**: `event_trigger_protocol_violated`
362    EventTriggerProtocolViolated,
363
364    // Class 3B — Savepoint Exception
365    /// **Code `3B000`**: `savepoint_exception`
366    SavepointException,
367    /// **Code `3B001`**: `invalid_savepoint_specification`
368    InvalidSavepointSpecification,
369
370    // Class 3D — Invalid Catalog Name
371    /// **Code `3D000`**: `invalid_catalog_name`
372    InvalidCatalogName,
373
374    // Class 3F — Invalid Schema Name
375    /// **Code `3F000`**: `invalid_schema_name`
376    InvalidSchemaName,
377
378    // Class 40 — Transaction Rollback
379    /// **Code `40000`**: `transaction_rollback`
380    TransactionRollback,
381    /// **Code `40002`**: `transaction_integrity_constraint_violation`
382    TransactionIntegrityConstraintViolation,
383    /// **Code `40001`**: `serialization_failure`
384    SerializationFailure,
385    /// **Code `40003`**: `statement_completion_unknown`
386    StatementCompletionUnknown,
387    /// **Code `40P01`**: `deadlock_detected`
388    DeadlockDetected,
389
390    // Class 42 — Syntax Error or Access Rule Violation
391    /// **Code `42000`**: `syntax_error_or_access_rule_violation`
392    SyntaxErrorOrAccessRuleViolation,
393    /// **Code `42601`**: `syntax_error`
394    SyntaxError,
395    /// **Code `42501`**: `insufficient_privilege`
396    InsufficientPrivilege,
397    /// **Code `42846`**: `cannot_coerce`
398    CannotCoerce,
399    /// **Code `42803`**: `grouping_error`
400    GroupingError,
401    /// **Code `42P20`**: `windowing_error`
402    WindowingError,
403    /// **Code `42P19`**: `invalid_recursion`
404    InvalidRecursion,
405    /// **Code `42830`**: `invalid_foreign_key`
406    InvalidForeignKey,
407    /// **Code `42602`**: `invalid_name`
408    InvalidName,
409    /// **Code `42622`**: `name_too_long`
410    NameTooLong,
411    /// **Code `42939`**: `reserved_name`
412    ReservedName,
413    /// **Code `42804`**: `datatype_mismatch`
414    DatatypeMismatch,
415    /// **Code `42P18`**: `indeterminate_datatype`
416    IndeterminateDatatype,
417    /// **Code `42P21`**: `collation_mismatch`
418    CollationMismatch,
419    /// **Code `42P22`**: `indeterminate_collation`
420    IndeterminateCollation,
421    /// **Code `42809`**: `wrong_object_type`
422    WrongObjectType,
423    /// **Code `428C9`**: `generated_always`
424    GeneratedAlways,
425    /// **Code `42703`**: `undefined_column`
426    UndefinedColumn,
427    /// **Code `42883`**: `undefined_function`
428    UndefinedFunction,
429    /// **Code `42P01`**: `undefined_table`
430    UndefinedTable,
431    /// **Code `42P02`**: `undefined_parameter`
432    UndefinedParameter,
433    /// **Code `42704`**: `undefined_object`
434    UndefinedObject,
435    /// **Code `42701`**: `duplicate_column`
436    DuplicateColumn,
437    /// **Code `42P03`**: `duplicate_cursor`
438    DuplicateCursor,
439    /// **Code `42P04`**: `duplicate_database`
440    DuplicateDatabase,
441    /// **Code `42723`**: `duplicate_function`
442    DuplicateFunction,
443    /// **Code `42P05`**: `duplicate_prepared_statement`
444    DuplicatePreparedStatement,
445    /// **Code `42P06`**: `duplicate_schema`
446    DuplicateSchema,
447    /// **Code `42P07`**: `duplicate_table`
448    DuplicateTable,
449    /// **Code `42712`**: `duplicate_alias`
450    DuplicateAlias,
451    /// **Code `42710`**: `duplicate_object`
452    DuplicateObject,
453    /// **Code `42702`**: `ambiguous_column`
454    AmbiguousColumn,
455    /// **Code `42725`**: `ambiguous_function`
456    AmbiguousFunction,
457    /// **Code `42P08`**: `ambiguous_parameter`
458    AmbiguousParameter,
459    /// **Code `42P09`**: `ambiguous_alias`
460    AmbiguousAlias,
461    /// **Code `42P10`**: `invalid_column_reference`
462    InvalidColumnReference,
463    /// **Code `42611`**: `invalid_column_definition`
464    InvalidColumnDefinition,
465    /// **Code `42P11`**: `invalid_cursor_definition`
466    InvalidCursorDefinition,
467    /// **Code `42P12`**: `invalid_database_definition`
468    InvalidDatabaseDefinition,
469    /// **Code `42P13`**: `invalid_function_definition`
470    InvalidFunctionDefinition,
471    /// **Code `42P14`**: `invalid_prepared_statement_definition`
472    InvalidPreparedStatementDefinition,
473    /// **Code `42P15`**: `invalid_schema_definition`
474    InvalidSchemaDefinition,
475    /// **Code `42P16`**: `invalid_table_definition`
476    InvalidTableDefinition,
477    /// **Code `42P17`**: `invalid_object_definition`
478    InvalidObjectDefinition,
479
480    // Class 44 — WITH CHECK OPTION Violation
481    /// **Code `44000`**: `with_check_option_violation`
482    WithCheckOptionViolation,
483
484    // Class 53 — Insufficient Resources
485    /// **Code `53000`**: `insufficient_resources`
486    InsufficientResources,
487    /// **Code `53100`**: `disk_full`
488    DiskFull,
489    /// **Code `53200`**: `out_of_memory`
490    OutOfMemory53200,
491    /// **Code `53300`**: `too_many_connections`
492    TooManyConnections,
493    /// **Code `53400`**: `configuration_limit_exceeded`
494    ConfigurationLimitExceeded,
495
496    // Class 54 — Program Limit Exceeded
497    /// **Code `54000`**: `program_limit_exceeded`
498    ProgramLimitExceeded,
499    /// **Code `54001`**: `statement_too_complex`
500    StatementTooComplex,
501    /// **Code `54011`**: `too_many_columns`
502    TooManyColumns,
503    /// **Code `54023`**: `too_many_arguments`
504    TooManyArguments,
505
506    // Class 55 — Object Not In Prerequisite State
507    /// **Code `55000`**: `object_not_in_prerequisite_state`
508    ObjectNotInPrerequisiteState,
509    /// **Code `55006`**: `object_in_use`
510    ObjectInUse,
511    /// **Code `55P02`**: `cant_change_runtime_param`
512    CantChangeRuntimeParam,
513    /// **Code `55P03`**: `lock_not_available`
514    LockNotAvailable,
515    /// **Code `55P04`**: `unsafe_new_enum_value_usage`
516    UnsafeNewEnumValueUsage,
517
518    // Class 57 — Operator Intervention
519    /// **Code `57000`**: `operator_intervention`
520    OperatorIntervention,
521    /// **Code `57014`**: `query_canceled`
522    QueryCanceled,
523    /// **Code `57P01`**: `admin_shutdown`
524    AdminShutdown,
525    /// **Code `57P02`**: `crash_shutdown`
526    CrashShutdown,
527    /// **Code `57P03`**: `cannot_connect_now`
528    CannotConnectNow,
529    /// **Code `57P04`**: `database_dropped`
530    DatabaseDropped,
531
532    // Class 58 — System Error
533    /// **Code `58000`**: `system_error`
534    SystemError,
535    /// **Code `58030`**: `io_error`
536    IoError,
537    /// **Code `58P01`**: `undefined_file`
538    UndefinedFile,
539    /// **Code `58P02`**: `duplicate_file`
540    DuplicateFile,
541
542    // Class 72 — Snapshot Failure
543    /// **Code `72000`**: `snapshot_too_old`
544    SnapshotTooOld,
545
546    // Class F0 — Configuration File Error
547    /// **Code `F0000`**: `config_file_error`
548    ConfigFileError,
549    /// **Code `F0001`**: `lock_file_exists`
550    LockFileExists,
551
552    // Class HV — Foreign Data Wrapper Error (SQL/MED)
553    /// **Code `HV000`**: `fdw_error`
554    FdwError,
555    /// **Code `HV005`**: `fdw_column_name_not_found`
556    FdwColumnNameNotFound,
557    /// **Code `HV002`**: `fdw_dynamic_parameter_value_needed`
558    FdwDynamicParameterValueNeeded,
559    /// **Code `HV010`**: `fdw_function_sequence_error`
560    FdwFunctionSequenceError,
561    /// **Code `HV021`**: `fdw_inconsistent_descriptor_information`
562    FdwInconsistentDescriptorInformation,
563    /// **Code `HV024`**: `fdw_invalid_attribute_value`
564    FdwInvalidAttributeValue,
565    /// **Code `HV007`**: `fdw_invalid_column_name`
566    FdwInvalidColumnName,
567    /// **Code `HV008`**: `fdw_invalid_column_number`
568    FdwInvalidColumnNumber,
569    /// **Code `HV004`**: `fdw_invalid_data_type`
570    FdwInvalidDataType,
571    /// **Code `HV006`**: `fdw_invalid_data_type_descriptors`
572    FdwInvalidDataTypeDescriptors,
573    /// **Code `HV091`**: `fdw_invalid_descriptor_field_identifier`
574    FdwInvalidDescriptorFieldIdentifier,
575    /// **Code `HV00B`**: `fdw_invalid_handle`
576    FdwInvalidHandle,
577    /// **Code `HV00C`**: `fdw_invalid_option_index`
578    FdwInvalidOptionIndex,
579    /// **Code `HV00D`**: `fdw_invalid_option_name`
580    FdwInvalidOptionName,
581    /// **Code `HV090`**: `fdw_invalid_string_length_or_buffer_length`
582    FdwInvalidStringLengthOrBufferLength,
583    /// **Code `HV00A`**: `fdw_invalid_string_format`
584    FdwInvalidStringFormat,
585    /// **Code `HV009`**: `fdw_invalid_use_of_null_pointer`
586    FdwInvalidUseOfNullPointer,
587    /// **Code `HV014`**: `fdw_too_many_handles`
588    FdwTooManyHandles,
589    /// **Code `HV001`**: `fdw_out_of_memory`
590    OutOfMemoryHV001,
591    /// **Code `HV00P`**: `fdw_no_schemas`
592    FdwNoSchemas,
593    /// **Code `HV00J`**: `fdw_option_name_not_found`
594    FdwOptionNameNotFound,
595    /// **Code `HV00K`**: `fdw_reply_handle`
596    FdwReplyHandle,
597    /// **Code `HV00Q`**: `fdw_schema_not_found`
598    FdwSchemaNotFound,
599    /// **Code `HV00R`**: `fdw_table_not_found`
600    FdwTableNotFound,
601    /// **Code `HV00L`**: `fdw_unable_to_create_execution`
602    FdwUnableToCreateExecution,
603    /// **Code `HV00M`**: `fdw_unable_to_create_reply`
604    FdwUnableToCreateReply,
605    /// **Code `HV00N`**: `fdw_unable_to_establish_connection`
606    FdwUnableToEstablishConnection,
607
608    // Class P0 — PL/pgSQL Error
609    /// **Code `P0000`**: `plpgsql_error`
610    PlpgsqlError,
611    /// **Code `P0001`**: `raise_exception`
612    RaiseException,
613    /// **Code `P0002`**: `no_data_found`
614    NoDataFound,
615    /// **Code `P0003`**: `too_many_rows`
616    TooManyRows,
617    /// **Code `P0004`**: `assert_failure`
618    AssertFailure,
619
620    // Class XX — Internal Error
621    /// **Code `XX000`**: `internal_error`
622    InternalError,
623    /// **Code `XX001`**: `data_corrupted`
624    DataCorrupted,
625    /// **Code `XX002`**: `index_corrupted`
626    IndexCorrupted,
627}
628
629impl PostgresErrorCode {
630    /// Returns true if the error code is a success.
631    pub fn is_success(self) -> bool {
632        self == PostgresErrorCode::SuccessfulCompletion
633    }
634
635    /// Returns true if the error code is a warning.
636    pub fn is_warning(self) -> bool {
637        self >= PostgresErrorCode::Warning && self < PostgresErrorCode::NoData
638    }
639
640    /// Returns true if the error code is an error.
641    pub fn is_error(self) -> bool {
642        self >= PostgresErrorCode::NoData
643    }
644
645    /// Returns the static five-character SQLSTATE string for the given error code.
646    pub const fn sqlstate(self) -> &'static str {
647        match self {
648            // Class 00
649            PostgresErrorCode::SuccessfulCompletion => "00000",
650            // Class 01
651            PostgresErrorCode::Warning => "01000",
652            PostgresErrorCode::DynamicResultSetsReturned => "0100C",
653            PostgresErrorCode::ImplicitZeroBitPadding => "01008",
654            PostgresErrorCode::NullValueEliminatedInSetFunction => "01003",
655            PostgresErrorCode::PrivilegeNotGranted => "01007",
656            PostgresErrorCode::PrivilegeNotRevoked => "01006",
657            PostgresErrorCode::StringDataRightTruncation01004 => "01004",
658            PostgresErrorCode::DeprecatedFeature => "01P01",
659            // Class 02
660            PostgresErrorCode::NoData => "02000",
661            PostgresErrorCode::NoAdditionalDynamicResultSetsReturned => "02001",
662            // Class 03
663            PostgresErrorCode::SqlStatementNotYetComplete => "03000",
664            // Class 08
665            PostgresErrorCode::ConnectionException => "08000",
666            PostgresErrorCode::ConnectionDoesNotExist => "08003",
667            PostgresErrorCode::ConnectionFailure => "08006",
668            PostgresErrorCode::SqlclientUnableToEstablishSqlconnection => "08001",
669            PostgresErrorCode::SqlserverRejectedEstablishmentOfSqlconnection => "08004",
670            PostgresErrorCode::TransactionResolutionUnknown => "08007",
671            PostgresErrorCode::ProtocolViolation => "08P01",
672            // Class 09
673            PostgresErrorCode::TriggeredActionException => "09000",
674            // Class 0A
675            PostgresErrorCode::FeatureNotSupported => "0A000",
676            // Class 0B
677            PostgresErrorCode::InvalidTransactionInitiation => "0B000",
678            // Class 0F
679            PostgresErrorCode::LocatorException => "0F000",
680            PostgresErrorCode::InvalidLocatorSpecification => "0F001",
681            // Class 0L
682            PostgresErrorCode::InvalidGrantor => "0L000",
683            PostgresErrorCode::InvalidGrantOperation => "0LP01",
684            // Class 0P
685            PostgresErrorCode::InvalidRoleSpecification => "0P000",
686            // Class 0Z
687            PostgresErrorCode::DiagnosticsException => "0Z000",
688            PostgresErrorCode::StackedDiagnosticsAccessedWithoutActiveHandler => "0Z002",
689            // Class 20
690            PostgresErrorCode::CaseNotFound => "20000",
691            // Class 21
692            PostgresErrorCode::CardinalityViolation => "21000",
693            // Class 22
694            PostgresErrorCode::DataException => "22000",
695            PostgresErrorCode::ArraySubscriptError => "2202E",
696            PostgresErrorCode::CharacterNotInRepertoire => "22021",
697            PostgresErrorCode::DatetimeFieldOverflow => "22008",
698            PostgresErrorCode::DivisionByZero => "22012",
699            PostgresErrorCode::ErrorInAssignment => "22005",
700            PostgresErrorCode::EscapeCharacterConflict => "2200B",
701            PostgresErrorCode::IndicatorOverflow => "22022",
702            PostgresErrorCode::IntervalFieldOverflow => "22015",
703            PostgresErrorCode::InvalidArgumentForLogarithm => "2201E",
704            PostgresErrorCode::InvalidArgumentForNtileFunction => "22014",
705            PostgresErrorCode::InvalidArgumentForNthValueFunction => "22016",
706            PostgresErrorCode::InvalidArgumentForPowerFunction => "2201F",
707            PostgresErrorCode::InvalidArgumentForWidthBucketFunction => "2201G",
708            PostgresErrorCode::InvalidCharacterValueForCast => "22018",
709            PostgresErrorCode::InvalidDatetimeFormat => "22007",
710            PostgresErrorCode::InvalidEscapeCharacter => "22019",
711            PostgresErrorCode::InvalidEscapeOctet => "2200D",
712            PostgresErrorCode::InvalidEscapeSequence => "22025",
713            PostgresErrorCode::NonstandardUseOfEscapeCharacter => "22P06",
714            PostgresErrorCode::InvalidIndicatorParameterValue => "22010",
715            PostgresErrorCode::InvalidParameterValue => "22023",
716            PostgresErrorCode::InvalidPrecedingOrFollowingSize => "22013",
717            PostgresErrorCode::InvalidRegularExpression => "2201B",
718            PostgresErrorCode::InvalidRowCountInLimitClause => "2201W",
719            PostgresErrorCode::InvalidRowCountInResultOffsetClause => "2201X",
720            PostgresErrorCode::InvalidTablesampleArgument => "2202H",
721            PostgresErrorCode::InvalidTablesampleRepeat => "2202G",
722            PostgresErrorCode::InvalidTimeZoneDisplacementValue => "22009",
723            PostgresErrorCode::InvalidUseOfEscapeCharacter => "2200C",
724            PostgresErrorCode::MostSpecificTypeMismatch => "2200G",
725            PostgresErrorCode::NullValueNotAllowed22004 => "22004",
726            PostgresErrorCode::NullValueNoIndicatorParameter => "22002",
727            PostgresErrorCode::NumericValueOutOfRange => "22003",
728            PostgresErrorCode::SequenceGeneratorLimitExceeded => "2200H",
729            PostgresErrorCode::StringDataLengthMismatch => "22026",
730            PostgresErrorCode::StringDataRightTruncation22001 => "22001",
731            PostgresErrorCode::SubstringError => "22011",
732            PostgresErrorCode::TrimError => "22027",
733            PostgresErrorCode::UnterminatedCString => "22024",
734            PostgresErrorCode::ZeroLengthCharacterString => "2200F",
735            PostgresErrorCode::FloatingPointException => "22P01",
736            PostgresErrorCode::InvalidTextRepresentation => "22P02",
737            PostgresErrorCode::InvalidBinaryRepresentation => "22P03",
738            PostgresErrorCode::BadCopyFileFormat => "22P04",
739            PostgresErrorCode::UntranslatableCharacter => "22P05",
740            PostgresErrorCode::NotAnXmlDocument => "2200L",
741            PostgresErrorCode::InvalidXmlDocument => "2200M",
742            PostgresErrorCode::InvalidXmlContent => "2200N",
743            PostgresErrorCode::InvalidXmlComment => "2200S",
744            PostgresErrorCode::InvalidXmlProcessingInstruction => "2200T",
745            PostgresErrorCode::DuplicateJsonObjectKeyValue => "22030",
746            PostgresErrorCode::InvalidArgumentForSqlJsonDatetimeFunction => "22031",
747            PostgresErrorCode::InvalidJsonText => "22032",
748            PostgresErrorCode::InvalidSqlJsonSubscript => "22033",
749            PostgresErrorCode::MoreThanOneSqlJsonItem => "22034",
750            PostgresErrorCode::NoSqlJsonItem => "22035",
751            PostgresErrorCode::NonNumericSqlJsonItem => "22036",
752            PostgresErrorCode::NonUniqueKeysInAJsonObject => "22037",
753            PostgresErrorCode::SingletonSqlJsonItemRequired => "22038",
754            PostgresErrorCode::SqlJsonArrayNotFound => "22039",
755            PostgresErrorCode::SqlJsonMemberNotFound => "2203A",
756            PostgresErrorCode::SqlJsonNumberNotFound => "2203B",
757            PostgresErrorCode::SqlJsonObjectNotFound => "2203C",
758            PostgresErrorCode::TooManyJsonArrayElements => "2203D",
759            PostgresErrorCode::TooManyJsonObjectMembers => "2203E",
760            PostgresErrorCode::SqlJsonScalarRequired => "2203F",
761            // Class 23
762            PostgresErrorCode::IntegrityConstraintViolation => "23000",
763            PostgresErrorCode::RestrictViolation => "23001",
764            PostgresErrorCode::NotNullViolation => "23502",
765            PostgresErrorCode::ForeignKeyViolation => "23503",
766            PostgresErrorCode::UniqueViolation => "23505",
767            PostgresErrorCode::CheckViolation => "23514",
768            PostgresErrorCode::ExclusionViolation => "23P01",
769            // Class 24
770            PostgresErrorCode::InvalidCursorState => "24000",
771            // Class 25
772            PostgresErrorCode::InvalidTransactionState => "25000",
773            PostgresErrorCode::ActiveSqlTransaction => "25001",
774            PostgresErrorCode::BranchTransactionAlreadyActive => "25002",
775            PostgresErrorCode::HeldCursorRequiresSameIsolationLevel => "25008",
776            PostgresErrorCode::InappropriateAccessModeForBranchTransaction => "25003",
777            PostgresErrorCode::InappropriateIsolationLevelForBranchTransaction => "25004",
778            PostgresErrorCode::NoActiveSqlTransactionForBranchTransaction => "25005",
779            PostgresErrorCode::ReadOnlySqlTransaction => "25006",
780            PostgresErrorCode::SchemaAndDataStatementMixingNotSupported => "25007",
781            PostgresErrorCode::NoActiveSqlTransaction => "25P01",
782            PostgresErrorCode::InFailedSqlTransaction => "25P02",
783            PostgresErrorCode::IdleInTransactionSessionTimeout => "25P03",
784            // Class 26
785            PostgresErrorCode::InvalidSqlStatementName => "26000",
786            // Class 27
787            PostgresErrorCode::TriggeredDataChangeViolation => "27000",
788            // Class 28
789            PostgresErrorCode::InvalidAuthorizationSpecification => "28000",
790            PostgresErrorCode::InvalidPassword => "28P01",
791            // Class 2B
792            PostgresErrorCode::DependentPrivilegeDescriptorsStillExist => "2B000",
793            PostgresErrorCode::DependentObjectsStillExist => "2BP01",
794            // Class 2D
795            PostgresErrorCode::InvalidTransactionTermination => "2D000",
796            // Class 2F
797            PostgresErrorCode::SqlRoutineException => "2F000",
798            PostgresErrorCode::FunctionExecutedNoReturnStatement => "2F005",
799            PostgresErrorCode::ModifyingSqlDataNotPermitted2F002 => "2F002",
800            PostgresErrorCode::ProhibitedSqlStatementAttempted2F003 => "2F003",
801            PostgresErrorCode::ReadingSqlDataNotPermitted2F004 => "2F004",
802            // Class 34
803            PostgresErrorCode::InvalidCursorName => "34000",
804            // Class 38
805            PostgresErrorCode::ExternalRoutineException => "38000",
806            PostgresErrorCode::ContainingSqlNotPermitted => "38001",
807            PostgresErrorCode::ModifyingSqlDataNotPermitted38002 => "38002",
808            PostgresErrorCode::ProhibitedSqlStatementAttempted38003 => "38003",
809            PostgresErrorCode::ReadingSqlDataNotPermitted38004 => "38004",
810            // Class 39
811            PostgresErrorCode::ExternalRoutineInvocationException => "39000",
812            PostgresErrorCode::InvalidSqlstateReturned => "39001",
813            PostgresErrorCode::NullValueNotAllowed39004 => "39004",
814            PostgresErrorCode::TriggerProtocolViolated => "39P01",
815            PostgresErrorCode::SrfProtocolViolated => "39P02",
816            PostgresErrorCode::EventTriggerProtocolViolated => "39P03",
817            // Class 3B
818            PostgresErrorCode::SavepointException => "3B000",
819            PostgresErrorCode::InvalidSavepointSpecification => "3B001",
820            // Class 3D
821            PostgresErrorCode::InvalidCatalogName => "3D000",
822            // Class 3F
823            PostgresErrorCode::InvalidSchemaName => "3F000",
824            // Class 40
825            PostgresErrorCode::TransactionRollback => "40000",
826            PostgresErrorCode::TransactionIntegrityConstraintViolation => "40002",
827            PostgresErrorCode::SerializationFailure => "40001",
828            PostgresErrorCode::StatementCompletionUnknown => "40003",
829            PostgresErrorCode::DeadlockDetected => "40P01",
830            // Class 42
831            PostgresErrorCode::SyntaxErrorOrAccessRuleViolation => "42000",
832            PostgresErrorCode::SyntaxError => "42601",
833            PostgresErrorCode::InsufficientPrivilege => "42501",
834            PostgresErrorCode::CannotCoerce => "42846",
835            PostgresErrorCode::GroupingError => "42803",
836            PostgresErrorCode::WindowingError => "42P20",
837            PostgresErrorCode::InvalidRecursion => "42P19",
838            PostgresErrorCode::InvalidForeignKey => "42830",
839            PostgresErrorCode::InvalidName => "42602",
840            PostgresErrorCode::NameTooLong => "42622",
841            PostgresErrorCode::ReservedName => "42939",
842            PostgresErrorCode::DatatypeMismatch => "42804",
843            PostgresErrorCode::IndeterminateDatatype => "42P18",
844            PostgresErrorCode::CollationMismatch => "42P21",
845            PostgresErrorCode::IndeterminateCollation => "42P22",
846            PostgresErrorCode::WrongObjectType => "42809",
847            PostgresErrorCode::GeneratedAlways => "428C9",
848            PostgresErrorCode::UndefinedColumn => "42703",
849            PostgresErrorCode::UndefinedFunction => "42883",
850            PostgresErrorCode::UndefinedTable => "42P01",
851            PostgresErrorCode::UndefinedParameter => "42P02",
852            PostgresErrorCode::UndefinedObject => "42704",
853            PostgresErrorCode::DuplicateColumn => "42701",
854            PostgresErrorCode::DuplicateCursor => "42P03",
855            PostgresErrorCode::DuplicateDatabase => "42P04",
856            PostgresErrorCode::DuplicateFunction => "42723",
857            PostgresErrorCode::DuplicatePreparedStatement => "42P05",
858            PostgresErrorCode::DuplicateSchema => "42P06",
859            PostgresErrorCode::DuplicateTable => "42P07",
860            PostgresErrorCode::DuplicateAlias => "42712",
861            PostgresErrorCode::DuplicateObject => "42710",
862            PostgresErrorCode::AmbiguousColumn => "42702",
863            PostgresErrorCode::AmbiguousFunction => "42725",
864            PostgresErrorCode::AmbiguousParameter => "42P08",
865            PostgresErrorCode::AmbiguousAlias => "42P09",
866            PostgresErrorCode::InvalidColumnReference => "42P10",
867            PostgresErrorCode::InvalidColumnDefinition => "42611",
868            PostgresErrorCode::InvalidCursorDefinition => "42P11",
869            PostgresErrorCode::InvalidDatabaseDefinition => "42P12",
870            PostgresErrorCode::InvalidFunctionDefinition => "42P13",
871            PostgresErrorCode::InvalidPreparedStatementDefinition => "42P14",
872            PostgresErrorCode::InvalidSchemaDefinition => "42P15",
873            PostgresErrorCode::InvalidTableDefinition => "42P16",
874            PostgresErrorCode::InvalidObjectDefinition => "42P17",
875            // Class 44
876            PostgresErrorCode::WithCheckOptionViolation => "44000",
877            // Class 53
878            PostgresErrorCode::InsufficientResources => "53000",
879            PostgresErrorCode::DiskFull => "53100",
880            PostgresErrorCode::OutOfMemory53200 => "53200",
881            PostgresErrorCode::TooManyConnections => "53300",
882            PostgresErrorCode::ConfigurationLimitExceeded => "53400",
883            // Class 54
884            PostgresErrorCode::ProgramLimitExceeded => "54000",
885            PostgresErrorCode::StatementTooComplex => "54001",
886            PostgresErrorCode::TooManyColumns => "54011",
887            PostgresErrorCode::TooManyArguments => "54023",
888            // Class 55
889            PostgresErrorCode::ObjectNotInPrerequisiteState => "55000",
890            PostgresErrorCode::ObjectInUse => "55006",
891            PostgresErrorCode::CantChangeRuntimeParam => "55P02",
892            PostgresErrorCode::LockNotAvailable => "55P03",
893            PostgresErrorCode::UnsafeNewEnumValueUsage => "55P04",
894            // Class 57
895            PostgresErrorCode::OperatorIntervention => "57000",
896            PostgresErrorCode::QueryCanceled => "57014",
897            PostgresErrorCode::AdminShutdown => "57P01",
898            PostgresErrorCode::CrashShutdown => "57P02",
899            PostgresErrorCode::CannotConnectNow => "57P03",
900            PostgresErrorCode::DatabaseDropped => "57P04",
901            // Class 58
902            PostgresErrorCode::SystemError => "58000",
903            PostgresErrorCode::IoError => "58030",
904            PostgresErrorCode::UndefinedFile => "58P01",
905            PostgresErrorCode::DuplicateFile => "58P02",
906            // Class 72
907            PostgresErrorCode::SnapshotTooOld => "72000",
908            // Class F0
909            PostgresErrorCode::ConfigFileError => "F0000",
910            PostgresErrorCode::LockFileExists => "F0001",
911            // Class HV
912            PostgresErrorCode::FdwError => "HV000",
913            PostgresErrorCode::FdwColumnNameNotFound => "HV005",
914            PostgresErrorCode::FdwDynamicParameterValueNeeded => "HV002",
915            PostgresErrorCode::FdwFunctionSequenceError => "HV010",
916            PostgresErrorCode::FdwInconsistentDescriptorInformation => "HV021",
917            PostgresErrorCode::FdwInvalidAttributeValue => "HV024",
918            PostgresErrorCode::FdwInvalidColumnName => "HV007",
919            PostgresErrorCode::FdwInvalidColumnNumber => "HV008",
920            PostgresErrorCode::FdwInvalidDataType => "HV004",
921            PostgresErrorCode::FdwInvalidDataTypeDescriptors => "HV006",
922            PostgresErrorCode::FdwInvalidDescriptorFieldIdentifier => "HV091",
923            PostgresErrorCode::FdwInvalidHandle => "HV00B",
924            PostgresErrorCode::FdwInvalidOptionIndex => "HV00C",
925            PostgresErrorCode::FdwInvalidOptionName => "HV00D",
926            PostgresErrorCode::FdwInvalidStringLengthOrBufferLength => "HV090",
927            PostgresErrorCode::FdwInvalidStringFormat => "HV00A",
928            PostgresErrorCode::FdwInvalidUseOfNullPointer => "HV009",
929            PostgresErrorCode::FdwTooManyHandles => "HV014",
930            PostgresErrorCode::OutOfMemoryHV001 => "HV001",
931            PostgresErrorCode::FdwNoSchemas => "HV00P",
932            PostgresErrorCode::FdwOptionNameNotFound => "HV00J",
933            PostgresErrorCode::FdwReplyHandle => "HV00K",
934            PostgresErrorCode::FdwSchemaNotFound => "HV00Q",
935            PostgresErrorCode::FdwTableNotFound => "HV00R",
936            PostgresErrorCode::FdwUnableToCreateExecution => "HV00L",
937            PostgresErrorCode::FdwUnableToCreateReply => "HV00M",
938            PostgresErrorCode::FdwUnableToEstablishConnection => "HV00N",
939            // Class P0
940            PostgresErrorCode::PlpgsqlError => "P0000",
941            PostgresErrorCode::RaiseException => "P0001",
942            PostgresErrorCode::NoDataFound => "P0002",
943            PostgresErrorCode::TooManyRows => "P0003",
944            PostgresErrorCode::AssertFailure => "P0004",
945            // Class XX
946            PostgresErrorCode::InternalError => "XX000",
947            PostgresErrorCode::DataCorrupted => "XX001",
948            PostgresErrorCode::IndexCorrupted => "XX002",
949        }
950    }
951}