Skip to content

PostgresQL error constants for use with Node.js

Notifications You must be signed in to change notification settings

kluplau/pg-error-constants

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PG Error Constants

PostgresQL error constants for use with Node.js. Use these to avoid code like if (err.code === '23505') and instead write if (err.code === UNIQUE_VIOLATION).

Installation

npm install --save pg-error-constants

Usage

const { UNIQUE_VIOLATION } = require('pg-error-constants')

// ...
  .catch((err) => {
    if (err.code === UNIQUE_VIOLATION && err.constraint === 'user_name_key') {
      throw new UserError('That name is already taken')
    }

    throw err
  })

Constants

Error Code Constant name
Class 00 — Successful Completion
00000SUCCESSFUL_COMPLETION
Class 01 — Warning
01000WARNING
0100CDYNAMIC_RESULT_SETS_RETURNED
01008IMPLICIT_ZERO_BIT_PADDING
01003NULL_VALUE_ELIMINATED_IN_SET_FUNCTION
01007PRIVILEGE_NOT_GRANTED
01006PRIVILEGE_NOT_REVOKED
01004STRING_DATA_RIGHT_TRUNCATION
01P01DEPRECATED_FEATURE
Class 02 — No Data (this is also a warning class per the SQL standard)
02000NO_DATA
02001NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED
Class 03 — SQL Statement Not Yet Complete
03000SQL_STATEMENT_NOT_YET_COMPLETE
Class 08 — Connection Exception
08000CONNECTION_EXCEPTION
08003CONNECTION_DOES_NOT_EXIST
08006CONNECTION_FAILURE
08001SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION
08004SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION
08007TRANSACTION_RESOLUTION_UNKNOWN
08P01PROTOCOL_VIOLATION
Class 09 — Triggered Action Exception
09000TRIGGERED_ACTION_EXCEPTION
Class 0A — Feature Not Supported
0A000FEATURE_NOT_SUPPORTED
Class 0B — Invalid Transaction Initiation
0B000INVALID_TRANSACTION_INITIATION
Class 0F — Locator Exception
0F000LOCATOR_EXCEPTION
0F001INVALID_LOCATOR_SPECIFICATION
Class 0L — Invalid Grantor
0L000INVALID_GRANTOR
0LP01INVALID_GRANT_OPERATION
Class 0P — Invalid Role Specification
0P000INVALID_ROLE_SPECIFICATION
Class 0Z — Diagnostics Exception
0Z000DIAGNOSTICS_EXCEPTION
0Z002STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER
Class 20 — Case Not Found
20000CASE_NOT_FOUND
Class 21 — Cardinality Violation
21000CARDINALITY_VIOLATION
Class 22 — Data Exception
22000DATA_EXCEPTION
2202EARRAY_SUBSCRIPT_ERROR
22021CHARACTER_NOT_IN_REPERTOIRE
22008DATETIME_FIELD_OVERFLOW
22012DIVISION_BY_ZERO
22005ERROR_IN_ASSIGNMENT
2200BESCAPE_CHARACTER_CONFLICT
22022INDICATOR_OVERFLOW
22015INTERVAL_FIELD_OVERFLOW
2201EINVALID_ARGUMENT_FOR_LOGARITHM
22014INVALID_ARGUMENT_FOR_NTILE_FUNCTION
22016INVALID_ARGUMENT_FOR_NTH_VALUE_FUNCTION
2201FINVALID_ARGUMENT_FOR_POWER_FUNCTION
2201GINVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION
22018INVALID_CHARACTER_VALUE_FOR_CAST
22007INVALID_DATETIME_FORMAT
22019INVALID_ESCAPE_CHARACTER
2200DINVALID_ESCAPE_OCTET
22025INVALID_ESCAPE_SEQUENCE
22P06NONSTANDARD_USE_OF_ESCAPE_CHARACTER
22010INVALID_INDICATOR_PARAMETER_VALUE
22023INVALID_PARAMETER_VALUE
2201BINVALID_REGULAR_EXPRESSION
2201WINVALID_ROW_COUNT_IN_LIMIT_CLAUSE
2201XINVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE
22009INVALID_TIME_ZONE_DISPLACEMENT_VALUE
2200CINVALID_USE_OF_ESCAPE_CHARACTER
2200GMOST_SPECIFIC_TYPE_MISMATCH
22004NULL_VALUE_NOT_ALLOWED
22002NULL_VALUE_NO_INDICATOR_PARAMETER
22003NUMERIC_VALUE_OUT_OF_RANGE
22026STRING_DATA_LENGTH_MISMATCH
22001STRING_DATA_RIGHT_TRUNCATION
22011SUBSTRING_ERROR
22027TRIM_ERROR
22024UNTERMINATED_C_STRING
2200FZERO_LENGTH_CHARACTER_STRING
22P01FLOATING_POINT_EXCEPTION
22P02INVALID_TEXT_REPRESENTATION
22P03INVALID_BINARY_REPRESENTATION
22P04BAD_COPY_FILE_FORMAT
22P05UNTRANSLATABLE_CHARACTER
2200LNOT_AN_XML_DOCUMENT
2200MINVALID_XML_DOCUMENT
2200NINVALID_XML_CONTENT
2200SINVALID_XML_COMMENT
2200TINVALID_XML_PROCESSING_INSTRUCTION
Class 23 — Integrity Constraint Violation
23000INTEGRITY_CONSTRAINT_VIOLATION
23001RESTRICT_VIOLATION
23502NOT_NULL_VIOLATION
23503FOREIGN_KEY_VIOLATION
23505UNIQUE_VIOLATION
23514CHECK_VIOLATION
23P01EXCLUSION_VIOLATION
Class 24 — Invalid Cursor State
24000INVALID_CURSOR_STATE
Class 25 — Invalid Transaction State
25000INVALID_TRANSACTION_STATE
25001ACTIVE_SQL_TRANSACTION
25002BRANCH_TRANSACTION_ALREADY_ACTIVE
25008HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL
25003INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION
25004INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION
25005NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION
25006READ_ONLY_SQL_TRANSACTION
25007SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED
25P01NO_ACTIVE_SQL_TRANSACTION
25P02IN_FAILED_SQL_TRANSACTION
Class 26 — Invalid SQL Statement Name
26000INVALID_SQL_STATEMENT_NAME
Class 27 — Triggered Data Change Violation
27000TRIGGERED_DATA_CHANGE_VIOLATION
Class 28 — Invalid Authorization Specification
28000INVALID_AUTHORIZATION_SPECIFICATION
28P01INVALID_PASSWORD
Class 2B — Dependent Privilege Descriptors Still Exist
2B000DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST
2BP01DEPENDENT_OBJECTS_STILL_EXIST
Class 2D — Invalid Transaction Termination
2D000INVALID_TRANSACTION_TERMINATION
Class 2F — SQL Routine Exception
2F000SQL_ROUTINE_EXCEPTION
2F005FUNCTION_EXECUTED_NO_RETURN_STATEMENT
2F002MODIFYING_SQL_DATA_NOT_PERMITTED
2F003PROHIBITED_SQL_STATEMENT_ATTEMPTED
2F004READING_SQL_DATA_NOT_PERMITTED
Class 34 — Invalid Cursor Name
34000INVALID_CURSOR_NAME
Class 38 — External Routine Exception
38000EXTERNAL_ROUTINE_EXCEPTION
38001CONTAINING_SQL_NOT_PERMITTED
38002MODIFYING_SQL_DATA_NOT_PERMITTED
38003PROHIBITED_SQL_STATEMENT_ATTEMPTED
38004READING_SQL_DATA_NOT_PERMITTED
Class 39 — External Routine Invocation Exception
39000EXTERNAL_ROUTINE_INVOCATION_EXCEPTION
39001INVALID_SQLSTATE_RETURNED
39004NULL_VALUE_NOT_ALLOWED
39P01TRIGGER_PROTOCOL_VIOLATED
39P02SRF_PROTOCOL_VIOLATED
Class 3B — Savepoint Exception
3B000SAVEPOINT_EXCEPTION
3B001INVALID_SAVEPOINT_SPECIFICATION
Class 3D — Invalid Catalog Name
3D000INVALID_CATALOG_NAME
Class 3F — Invalid Schema Name
3F000INVALID_SCHEMA_NAME
Class 40 — Transaction Rollback
40000TRANSACTION_ROLLBACK
40002TRANSACTION_INTEGRITY_CONSTRAINT_VIOLATION
40001SERIALIZATION_FAILURE
40003STATEMENT_COMPLETION_UNKNOWN
40P01DEADLOCK_DETECTED
Class 42 — Syntax Error or Access Rule Violation
42000SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION
42601SYNTAX_ERROR
42501INSUFFICIENT_PRIVILEGE
42846CANNOT_COERCE
42803GROUPING_ERROR
42P20WINDOWING_ERROR
42P19INVALID_RECURSION
42830INVALID_FOREIGN_KEY
42602INVALID_NAME
42622NAME_TOO_LONG
42939RESERVED_NAME
42804DATATYPE_MISMATCH
42P18INDETERMINATE_DATATYPE
42P21COLLATION_MISMATCH
42P22INDETERMINATE_COLLATION
42809WRONG_OBJECT_TYPE
42703UNDEFINED_COLUMN
42883UNDEFINED_FUNCTION
42P01UNDEFINED_TABLE
42P02UNDEFINED_PARAMETER
42704UNDEFINED_OBJECT
42701DUPLICATE_COLUMN
42P03DUPLICATE_CURSOR
42P04DUPLICATE_DATABASE
42723DUPLICATE_FUNCTION
42P05DUPLICATE_PREPARED_STATEMENT
42P06DUPLICATE_SCHEMA
42P07DUPLICATE_TABLE
42712DUPLICATE_ALIAS
42710DUPLICATE_OBJECT
42702AMBIGUOUS_COLUMN
42725AMBIGUOUS_FUNCTION
42P08AMBIGUOUS_PARAMETER
42P09AMBIGUOUS_ALIAS
42P10INVALID_COLUMN_REFERENCE
42611INVALID_COLUMN_DEFINITION
42P11INVALID_CURSOR_DEFINITION
42P12INVALID_DATABASE_DEFINITION
42P13INVALID_FUNCTION_DEFINITION
42P14INVALID_PREPARED_STATEMENT_DEFINITION
42P15INVALID_SCHEMA_DEFINITION
42P16INVALID_TABLE_DEFINITION
42P17INVALID_OBJECT_DEFINITION
Class 44 — WITH CHECK OPTION Violation
44000WITH_CHECK_OPTION_VIOLATION
Class 53 — Insufficient Resources
53000INSUFFICIENT_RESOURCES
53100DISK_FULL
53200OUT_OF_MEMORY
53300TOO_MANY_CONNECTIONS
53400CONFIGURATION_LIMIT_EXCEEDED
Class 54 — Program Limit Exceeded
54000PROGRAM_LIMIT_EXCEEDED
54001STATEMENT_TOO_COMPLEX
54011TOO_MANY_COLUMNS
54023TOO_MANY_ARGUMENTS
Class 55 — Object Not In Prerequisite State
55000OBJECT_NOT_IN_PREREQUISITE_STATE
55006OBJECT_IN_USE
55P02CANT_CHANGE_RUNTIME_PARAM
55P03LOCK_NOT_AVAILABLE
Class 57 — Operator Intervention
57000OPERATOR_INTERVENTION
57014QUERY_CANCELED
57P01ADMIN_SHUTDOWN
57P02CRASH_SHUTDOWN
57P03CANNOT_CONNECT_NOW
57P04DATABASE_DROPPED
Class 58 — System Error (errors external to PostgreSQL itself)
58000SYSTEM_ERROR
58030IO_ERROR
58P01UNDEFINED_FILE
58P02DUPLICATE_FILE
Class F0 — Configuration File Error
F0000CONFIG_FILE_ERROR
F0001LOCK_FILE_EXISTS
Class HV — Foreign Data Wrapper Error (SQL/MED)
HV000FDW_ERROR
HV005FDW_COLUMN_NAME_NOT_FOUND
HV002FDW_DYNAMIC_PARAMETER_VALUE_NEEDED
HV010FDW_FUNCTION_SEQUENCE_ERROR
HV021FDW_INCONSISTENT_DESCRIPTOR_INFORMATION
HV024FDW_INVALID_ATTRIBUTE_VALUE
HV007FDW_INVALID_COLUMN_NAME
HV008FDW_INVALID_COLUMN_NUMBER
HV004FDW_INVALID_DATA_TYPE
HV006FDW_INVALID_DATA_TYPE_DESCRIPTORS
HV091FDW_INVALID_DESCRIPTOR_FIELD_IDENTIFIER
HV00BFDW_INVALID_HANDLE
HV00CFDW_INVALID_OPTION_INDEX
HV00DFDW_INVALID_OPTION_NAME
HV090FDW_INVALID_STRING_LENGTH_OR_BUFFER_LENGTH
HV00AFDW_INVALID_STRING_FORMAT
HV009FDW_INVALID_USE_OF_NULL_POINTER
HV014FDW_TOO_MANY_HANDLES
HV001FDW_OUT_OF_MEMORY
HV00PFDW_NO_SCHEMAS
HV00JFDW_OPTION_NAME_NOT_FOUND
HV00KFDW_REPLY_HANDLE
HV00QFDW_SCHEMA_NOT_FOUND
HV00RFDW_TABLE_NOT_FOUND
HV00LFDW_UNABLE_TO_CREATE_EXECUTION
HV00MFDW_UNABLE_TO_CREATE_REPLY
HV00NFDW_UNABLE_TO_ESTABLISH_CONNECTION
Class P0 — PL/pgSQL Error
P0000PLPGSQL_ERROR
P0001RAISE_EXCEPTION
P0002NO_DATA_FOUND
P0003TOO_MANY_ROWS
Class XX — Internal Error
XX000INTERNAL_ERROR
XX001DATA_CORRUPTED
XX002INDEX_CORRUPTED

About

PostgresQL error constants for use with Node.js

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%