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)`.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
pg-error-constants
3131.0.06 years ago6 years agoMinified + gzip package size for pg-error-constants in KB

Readme

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
00000SUCCESSFULCOMPLETION
Class 01 — Warning
01000WARNING
0100CDYNAMICRESULTSETSRETURNED
01008IMPLICITZEROBITPADDING
01003NULLVALUEELIMINATEDINSETFUNCTION
01007PRIVILEGENOTGRANTED
01006PRIVILEGENOTREVOKED
01004STRINGDATARIGHTTRUNCATION
01P01DEPRECATEDFEATURE
Class 02 — No Data (this is also a warning class per the SQL standard)
02000NODATA
02001NOADDITIONALDYNAMICRESULTSETSRETURNED
Class 03 — SQL Statement Not Yet Complete
03000SQLSTATEMENTNOTYETCOMPLETE
Class 08 — Connection Exception
08000CONNECTIONEXCEPTION
08003CONNECTIONDOESNOTEXIST
08006CONNECTIONFAILURE
08001SQLCLIENTUNABLETOESTABLISHSQLCONNECTION
08004SQLSERVERREJECTEDESTABLISHMENTOFSQLCONNECTION
08007TRANSACTIONRESOLUTIONUNKNOWN
08P01PROTOCOLVIOLATION
Class 09 — Triggered Action Exception
09000TRIGGEREDACTIONEXCEPTION
Class 0A — Feature Not Supported
0A000FEATURENOTSUPPORTED
Class 0B — Invalid Transaction Initiation
0B000INVALIDTRANSACTIONINITIATION
Class 0F — Locator Exception
0F000LOCATOREXCEPTION
0F001INVALIDLOCATORSPECIFICATION
Class 0L — Invalid Grantor
0L000INVALIDGRANTOR
0LP01INVALIDGRANTOPERATION
Class 0P — Invalid Role Specification
0P000INVALIDROLESPECIFICATION
Class 0Z — Diagnostics Exception
0Z000DIAGNOSTICSEXCEPTION
0Z002STACKEDDIAGNOSTICSACCESSEDWITHOUTACTIVEHANDLER
Class 20 — Case Not Found
20000CASENOTFOUND
Class 21 — Cardinality Violation
21000CARDINALITYVIOLATION
Class 22 — Data Exception
22000DATAEXCEPTION
2202EARRAYSUBSCRIPTERROR
22021CHARACTERNOTINREPERTOIRE
22008DATETIMEFIELDOVERFLOW
22012DIVISIONBYZERO
22005ERRORINASSIGNMENT
2200BESCAPECHARACTERCONFLICT
22022INDICATOROVERFLOW
22015INTERVALFIELDOVERFLOW
2201EINVALIDARGUMENTFORLOGARITHM
22014INVALIDARGUMENTFORNTILEFUNCTION
22016INVALIDARGUMENTFORNTHVALUEFUNCTION
2201FINVALIDARGUMENTFORPOWERFUNCTION
2201GINVALIDARGUMENTFORWIDTHBUCKETFUNCTION
22018INVALIDCHARACTERVALUEFORCAST
22007INVALIDDATETIMEFORMAT
22019INVALIDESCAPECHARACTER
2200DINVALIDESCAPEOCTET
22025INVALIDESCAPESEQUENCE
22P06NONSTANDARDUSEOFESCAPECHARACTER
22010INVALIDINDICATORPARAMETERVALUE
22023INVALIDPARAMETERVALUE
2201BINVALIDREGULAREXPRESSION
2201WINVALIDROWCOUNTINLIMITCLAUSE
2201XINVALIDROWCOUNTINRESULTOFFSETCLAUSE
22009INVALIDTIMEZONEDISPLACEMENTVALUE
2200CINVALIDUSEOFESCAPECHARACTER
2200GMOSTSPECIFICTYPEMISMATCH
22004NULLVALUENOTALLOWED
22002NULLVALUENOINDICATORPARAMETER
22003NUMERICVALUEOUTOFRANGE
22026STRINGDATALENGTHMISMATCH
22001STRINGDATARIGHTTRUNCATION
22011SUBSTRINGERROR
22027TRIMERROR
22024UNTERMINATEDCSTRING
2200FZEROLENGTHCHARACTERSTRING
22P01FLOATINGPOINTEXCEPTION
22P02INVALIDTEXTREPRESENTATION
22P03INVALIDBINARYREPRESENTATION
22P04BADCOPYFILEFORMAT
22P05UNTRANSLATABLECHARACTER
2200LNOTANXMLDOCUMENT
2200MINVALIDXMLDOCUMENT
2200NINVALIDXMLCONTENT
2200SINVALIDXMLCOMMENT
2200TINVALIDXMLPROCESSINGINSTRUCTION
Class 23 — Integrity Constraint Violation
23000INTEGRITYCONSTRAINTVIOLATION
23001RESTRICTVIOLATION
23502NOTNULLVIOLATION
23503FOREIGNKEYVIOLATION
23505UNIQUEVIOLATION
23514CHECKVIOLATION
23P01EXCLUSIONVIOLATION
Class 24 — Invalid Cursor State
24000INVALIDCURSORSTATE
Class 25 — Invalid Transaction State
25000INVALIDTRANSACTIONSTATE
25001ACTIVESQLTRANSACTION
25002BRANCHTRANSACTIONALREADYACTIVE
25008HELDCURSORREQUIRESSAMEISOLATIONLEVEL
25003INAPPROPRIATEACCESSMODEFORBRANCHTRANSACTION
25004INAPPROPRIATEISOLATIONLEVELFORBRANCHTRANSACTION
25005NOACTIVESQLTRANSACTIONFORBRANCHTRANSACTION
25006READONLYSQLTRANSACTION
25007SCHEMAANDDATASTATEMENTMIXINGNOTSUPPORTED
25P01NOACTIVESQLTRANSACTION
25P02INFAILEDSQLTRANSACTION
Class 26 — Invalid SQL Statement Name
26000INVALIDSQLSTATEMENTNAME
Class 27 — Triggered Data Change Violation
27000TRIGGEREDDATACHANGEVIOLATION
Class 28 — Invalid Authorization Specification
28000INVALIDAUTHORIZATIONSPECIFICATION
28P01INVALIDPASSWORD
Class 2B — Dependent Privilege Descriptors Still Exist
2B000DEPENDENTPRIVILEGEDESCRIPTORSSTILLEXIST
2BP01DEPENDENTOBJECTSSTILLEXIST
Class 2D — Invalid Transaction Termination
2D000INVALIDTRANSACTIONTERMINATION
Class 2F — SQL Routine Exception
2F000SQLROUTINEEXCEPTION
2F005FUNCTIONEXECUTEDNORETURNSTATEMENT
2F002MODIFYINGSQLDATANOTPERMITTED
2F003PROHIBITEDSQLSTATEMENTATTEMPTED
2F004READINGSQLDATANOTPERMITTED
Class 34 — Invalid Cursor Name
34000INVALIDCURSORNAME
Class 38 — External Routine Exception
38000EXTERNALROUTINEEXCEPTION
38001CONTAININGSQLNOTPERMITTED
38002MODIFYINGSQLDATANOTPERMITTED
38003PROHIBITEDSQLSTATEMENTATTEMPTED
38004READINGSQLDATANOTPERMITTED
Class 39 — External Routine Invocation Exception
39000EXTERNALROUTINEINVOCATIONEXCEPTION
39001INVALIDSQLSTATERETURNED
39004NULLVALUENOTALLOWED
39P01TRIGGERPROTOCOLVIOLATED
39P02SRFPROTOCOLVIOLATED
Class 3B — Savepoint Exception
3B000SAVEPOINTEXCEPTION
3B001INVALIDSAVEPOINTSPECIFICATION
Class 3D — Invalid Catalog Name
3D000INVALIDCATALOGNAME
Class 3F — Invalid Schema Name
3F000INVALIDSCHEMANAME
Class 40 — Transaction Rollback
40000TRANSACTIONROLLBACK
40002TRANSACTIONINTEGRITYCONSTRAINTVIOLATION
40001SERIALIZATIONFAILURE
40003STATEMENTCOMPLETIONUNKNOWN
40P01DEADLOCKDETECTED
Class 42 — Syntax Error or Access Rule Violation
42000SYNTAXERRORORACCESSRULEVIOLATION
42601SYNTAXERROR
42501INSUFFICIENTPRIVILEGE
42846CANNOTCOERCE
42803GROUPINGERROR
42P20WINDOWINGERROR
42P19INVALIDRECURSION
42830INVALIDFOREIGNKEY
42602INVALIDNAME
42622NAMETOOLONG
42939RESERVEDNAME
42804DATATYPEMISMATCH
42P18INDETERMINATEDATATYPE
42P21COLLATIONMISMATCH
42P22INDETERMINATECOLLATION
42809WRONGOBJECTTYPE
42703UNDEFINEDCOLUMN
42883UNDEFINEDFUNCTION
42P01UNDEFINEDTABLE
42P02UNDEFINEDPARAMETER
42704UNDEFINEDOBJECT
42701DUPLICATECOLUMN
42P03DUPLICATECURSOR
42P04DUPLICATEDATABASE
42723DUPLICATEFUNCTION
42P05DUPLICATEPREPAREDSTATEMENT
42P06DUPLICATESCHEMA
42P07DUPLICATETABLE
42712DUPLICATEALIAS
42710DUPLICATEOBJECT
42702AMBIGUOUSCOLUMN
42725AMBIGUOUSFUNCTION
42P08AMBIGUOUSPARAMETER
42P09AMBIGUOUSALIAS
42P10INVALIDCOLUMNREFERENCE
42611INVALIDCOLUMNDEFINITION
42P11INVALIDCURSORDEFINITION
42P12INVALIDDATABASEDEFINITION
42P13INVALIDFUNCTIONDEFINITION
42P14INVALIDPREPAREDSTATEMENTDEFINITION
42P15INVALIDSCHEMADEFINITION
42P16INVALIDTABLEDEFINITION
42P17INVALIDOBJECTDEFINITION
Class 44 — WITH CHECK OPTION Violation
44000WITHCHECKOPTIONVIOLATION
Class 53 — Insufficient Resources
53000INSUFFICIENTRESOURCES
53100DISKFULL
53200OUTOFMEMORY
53300TOOMANYCONNECTIONS
53400CONFIGURATIONLIMITEXCEEDED
Class 54 — Program Limit Exceeded
54000PROGRAMLIMITEXCEEDED
54001STATEMENTTOOCOMPLEX
54011TOOMANYCOLUMNS
54023TOOMANYARGUMENTS
Class 55 — Object Not In Prerequisite State
55000OBJECTNOTINPREREQUISITESTATE
55006OBJECTINUSE
55P02CANTCHANGERUNTIMEPARAM
55P03LOCKNOTAVAILABLE
Class 57 — Operator Intervention
57000OPERATORINTERVENTION
57014QUERYCANCELED
57P01ADMINSHUTDOWN
57P02CRASHSHUTDOWN
57P03CANNOTCONNECTNOW
57P04DATABASEDROPPED
Class 58 — System Error (errors external to PostgreSQL itself)
58000SYSTEMERROR
58030IOERROR
58P01UNDEFINEDFILE
58P02DUPLICATEFILE
Class F0 — Configuration File Error
F0000CONFIGFILEERROR
F0001LOCKFILEEXISTS
Class HV — Foreign Data Wrapper Error (SQL/MED)
HV000FDWERROR
HV005FDWCOLUMNNAMENOTFOUND
HV002FDWDYNAMICPARAMETERVALUENEEDED
HV010FDWFUNCTIONSEQUENCEERROR
HV021FDWINCONSISTENTDESCRIPTORINFORMATION
HV024FDWINVALIDATTRIBUTEVALUE
HV007FDWINVALIDCOLUMNNAME
HV008FDWINVALIDCOLUMNNUMBER
HV004FDWINVALIDDATATYPE
HV006FDWINVALIDDATATYPEDESCRIPTORS
HV091FDWINVALIDDESCRIPTORFIELDIDENTIFIER
HV00BFDWINVALIDHANDLE
HV00CFDWINVALIDOPTIONINDEX
HV00DFDWINVALIDOPTIONNAME
HV090FDWINVALIDSTRINGLENGTHORBUFFERLENGTH
HV00AFDWINVALIDSTRINGFORMAT
HV009FDWINVALIDUSEOFNULLPOINTER
HV014FDWTOOMANYHANDLES
HV001FDWOUTOFMEMORY
HV00PFDWNOSCHEMAS
HV00JFDWOPTIONNAMENOTFOUND
HV00KFDWREPLYHANDLE
HV00QFDWSCHEMANOTFOUND
HV00RFDWTABLENOTFOUND
HV00LFDWUNABLETOCREATEEXECUTION
HV00MFDWUNABLETOCREATEREPLY
HV00NFDWUNABLETOESTABLISHCONNECTION
Class P0 — PL/pgSQL Error
P0000PLPGSQLERROR
P0001RAISEEXCEPTION
P0002NODATAFOUND
P0003TOOMANYROWS
Class XX — Internal Error
XX000INTERNALERROR
XX001DATACORRUPTED
XX002INDEXCORRUPTED