Debian Codegraph @

errcode.go

raw symbols SCIP
1 // Package pgerrcode contains constants for PostgreSQL error codes.
2 package pgerrcode
3
4 // Source: https://www.postgresql.org/docs/16/errcodes-appendix.html
5 // See gen.rb for script that can convert the error code table to Go code.
6
7 const (
8
9 // Class 00 — Successful Completion
10 SuccessfulCompletion = "00000"
11
12 // Class 01 — Warning
13 Warning = "01000"
14 DynamicResultSetsReturned = "0100C"
15 ImplicitZeroBitPadding = "01008"
16 NullValueEliminatedInSetFunction = "01003"
17 PrivilegeNotGranted = "01007"
18 PrivilegeNotRevoked = "01006"
19 StringDataRightTruncationWarning = "01004"
20 DeprecatedFeature = "01P01"
21
22 // Class 02 — No Data (this is also a warning class per the SQL standard)
23 NoData = "02000"
24 NoAdditionalDynamicResultSetsReturned = "02001"
25
26 // Class 03 — SQL Statement Not Yet Complete
27 SQLStatementNotYetComplete = "03000"
28
29 // Class 08 — Connection Exception
30 ConnectionException = "08000"
31 ConnectionDoesNotExist = "08003"
32 ConnectionFailure = "08006"
33 SQLClientUnableToEstablishSQLConnection = "08001"
34 SQLServerRejectedEstablishmentOfSQLConnection = "08004"
35 TransactionResolutionUnknown = "08007"
36 ProtocolViolation = "08P01"
37
38 // Class 09 — Triggered Action Exception
39 TriggeredActionException = "09000"
40
41 // Class 0A — Feature Not Supported
42 FeatureNotSupported = "0A000"
43
44 // Class 0B — Invalid Transaction Initiation
45 InvalidTransactionInitiation = "0B000"
46
47 // Class 0F — Locator Exception
48 LocatorException = "0F000"
49 InvalidLocatorSpecification = "0F001"
50
51 // Class 0L — Invalid Grantor
52 InvalidGrantor = "0L000"
53 InvalidGrantOperation = "0LP01"
54
55 // Class 0P — Invalid Role Specification
56 InvalidRoleSpecification = "0P000"
57
58 // Class 0Z — Diagnostics Exception
59 DiagnosticsException = "0Z000"
60 StackedDiagnosticsAccessedWithoutActiveHandler = "0Z002"
61
62 // Class 20 — Case Not Found
63 CaseNotFound = "20000"
64
65 // Class 21 — Cardinality Violation
66 CardinalityViolation = "21000"
67
68 // Class 22 — Data Exception
69 DataException = "22000"
70 ArraySubscriptError = "2202E"
71 CharacterNotInRepertoire = "22021"
72 DatetimeFieldOverflow = "22008"
73 DivisionByZero = "22012"
74 ErrorInAssignment = "22005"
75 EscapeCharacterConflict = "2200B"
76 IndicatorOverflow = "22022"
77 IntervalFieldOverflow = "22015"
78 InvalidArgumentForLogarithm = "2201E"
79 InvalidArgumentForNtileFunction = "22014"
80 InvalidArgumentForNthValueFunction = "22016"
81 InvalidArgumentForPowerFunction = "2201F"
82 InvalidArgumentForWidthBucketFunction = "2201G"
83 InvalidCharacterValueForCast = "22018"
84 InvalidDatetimeFormat = "22007"
85 InvalidEscapeCharacter = "22019"
86 InvalidEscapeOctet = "2200D"
87 InvalidEscapeSequence = "22025"
88 NonstandardUseOfEscapeCharacter = "22P06"
89 InvalidIndicatorParameterValue = "22010"
90 InvalidParameterValue = "22023"
91 InvalidPrecedingOrFollowingSize = "22013"
92 InvalidRegularExpression = "2201B"
93 InvalidRowCountInLimitClause = "2201W"
94 InvalidRowCountInResultOffsetClause = "2201X"
95 InvalidTablesampleArgument = "2202H"
96 InvalidTablesampleRepeat = "2202G"
97 InvalidTimeZoneDisplacementValue = "22009"
98 InvalidUseOfEscapeCharacter = "2200C"
99 MostSpecificTypeMismatch = "2200G"
100 NullValueNotAllowedDataException = "22004"
101 NullValueNoIndicatorParameter = "22002"
102 NumericValueOutOfRange = "22003"
103 SequenceGeneratorLimitExceeded = "2200H"
104 StringDataLengthMismatch = "22026"
105 StringDataRightTruncationDataException = "22001"
106 SubstringError = "22011"
107 TrimError = "22027"
108 UnterminatedCString = "22024"
109 ZeroLengthCharacterString = "2200F"
110 FloatingPointException = "22P01"
111 InvalidTextRepresentation = "22P02"
112 InvalidBinaryRepresentation = "22P03"
113 BadCopyFileFormat = "22P04"
114 UntranslatableCharacter = "22P05"
115 NotAnXMLDocument = "2200L"
116 InvalidXMLDocument = "2200M"
117 InvalidXMLContent = "2200N"
118 InvalidXMLComment = "2200S"
119 InvalidXMLProcessingInstruction = "2200T"
120 DuplicateJSONObjectKeyValue = "22030"
121 InvalidArgumentForSQLJSONDatetimeFunction = "22031"
122 InvalidJSONText = "22032"
123 InvalidSQLJSONSubscript = "22033"
124 MoreThanOneSQLJSONItem = "22034"
125 NoSQLJSONItem = "22035"
126 NonNumericSQLJSONItem = "22036"
127 NonUniqueKeysInAJSONObject = "22037"
128 SingletonSQLJSONItemRequired = "22038"
129 SQLJSONArrayNotFound = "22039"
130 SQLJSONMemberNotFound = "2203A"
131 SQLJSONNumberNotFound = "2203B"
132 SQLJSONObjectNotFound = "2203C"
133 TooManyJSONArrayElements = "2203D"
134 TooManyJSONObjectMembers = "2203E"
135 SQLJSONScalarRequired = "2203F"
136 SQLJSONItemCannotBeCastToTargetType = "2203G"
137
138 // Class 23 — Integrity Constraint Violation
139 IntegrityConstraintViolation = "23000"
140 RestrictViolation = "23001"
141 NotNullViolation = "23502"
142 ForeignKeyViolation = "23503"
143 UniqueViolation = "23505"
144 CheckViolation = "23514"
145 ExclusionViolation = "23P01"
146
147 // Class 24 — Invalid Cursor State
148 InvalidCursorState = "24000"
149
150 // Class 25 — Invalid Transaction State
151 InvalidTransactionState = "25000"
152 ActiveSQLTransaction = "25001"
153 BranchTransactionAlreadyActive = "25002"
154 HeldCursorRequiresSameIsolationLevel = "25008"
155 InappropriateAccessModeForBranchTransaction = "25003"
156 InappropriateIsolationLevelForBranchTransaction = "25004"
157 NoActiveSQLTransactionForBranchTransaction = "25005"
158 ReadOnlySQLTransaction = "25006"
159 SchemaAndDataStatementMixingNotSupported = "25007"
160 NoActiveSQLTransaction = "25P01"
161 InFailedSQLTransaction = "25P02"
162 IdleInTransactionSessionTimeout = "25P03"
163
164 // Class 26 — Invalid SQL Statement Name
165 InvalidSQLStatementName = "26000"
166
167 // Class 27 — Triggered Data Change Violation
168 TriggeredDataChangeViolation = "27000"
169
170 // Class 28 — Invalid Authorization Specification
171 InvalidAuthorizationSpecification = "28000"
172 InvalidPassword = "28P01"
173
174 // Class 2B — Dependent Privilege Descriptors Still Exist
175 DependentPrivilegeDescriptorsStillExist = "2B000"
176 DependentObjectsStillExist = "2BP01"
177
178 // Class 2D — Invalid Transaction Termination
179 InvalidTransactionTermination = "2D000"
180
181 // Class 2F — SQL Routine Exception
182 SQLRoutineException = "2F000"
183 FunctionExecutedNoReturnStatement = "2F005"
184 ModifyingSQLDataNotPermittedSQLRoutineException = "2F002"
185 ProhibitedSQLStatementAttemptedSQLRoutineException = "2F003"
186 ReadingSQLDataNotPermittedSQLRoutineException = "2F004"
187
188 // Class 34 — Invalid Cursor Name
189 InvalidCursorName = "34000"
190
191 // Class 38 — External Routine Exception
192 ExternalRoutineException = "38000"
193 ContainingSQLNotPermitted = "38001"
194 ModifyingSQLDataNotPermittedExternalRoutineException = "38002"
195 ProhibitedSQLStatementAttemptedExternalRoutineException = "38003"
196 ReadingSQLDataNotPermittedExternalRoutineException = "38004"
197
198 // Class 39 — External Routine Invocation Exception
199 ExternalRoutineInvocationException = "39000"
200 InvalidSQLstateReturned = "39001"
201 NullValueNotAllowedExternalRoutineInvocationException = "39004"
202 TriggerProtocolViolated = "39P01"
203 SRFProtocolViolated = "39P02"
204 EventTriggerProtocolViolated = "39P03"
205
206 // Class 3B — Savepoint Exception
207 SavepointException = "3B000"
208 InvalidSavepointSpecification = "3B001"
209
210 // Class 3D — Invalid Catalog Name
211 InvalidCatalogName = "3D000"
212
213 // Class 3F — Invalid Schema Name
214 InvalidSchemaName = "3F000"
215
216 // Class 40 — Transaction Rollback
217 TransactionRollback = "40000"
218 TransactionIntegrityConstraintViolation = "40002"
219 SerializationFailure = "40001"
220 StatementCompletionUnknown = "40003"
221 DeadlockDetected = "40P01"
222
223 // Class 42 — Syntax Error or Access Rule Violation
224 SyntaxErrorOrAccessRuleViolation = "42000"
225 SyntaxError = "42601"
226 InsufficientPrivilege = "42501"
227 CannotCoerce = "42846"
228 GroupingError = "42803"
229 WindowingError = "42P20"
230 InvalidRecursion = "42P19"
231 InvalidForeignKey = "42830"
232 InvalidName = "42602"
233 NameTooLong = "42622"
234 ReservedName = "42939"
235 DatatypeMismatch = "42804"
236 IndeterminateDatatype = "42P18"
237 CollationMismatch = "42P21"
238 IndeterminateCollation = "42P22"
239 WrongObjectType = "42809"
240 GeneratedAlways = "428C9"
241 UndefinedColumn = "42703"
242 UndefinedFunction = "42883"
243 UndefinedTable = "42P01"
244 UndefinedParameter = "42P02"
245 UndefinedObject = "42704"
246 DuplicateColumn = "42701"
247 DuplicateCursor = "42P03"
248 DuplicateDatabase = "42P04"
249 DuplicateFunction = "42723"
250 DuplicatePreparedStatement = "42P05"
251 DuplicateSchema = "42P06"
252 DuplicateTable = "42P07"
253 DuplicateAlias = "42712"
254 DuplicateObject = "42710"
255 AmbiguousColumn = "42702"
256 AmbiguousFunction = "42725"
257 AmbiguousParameter = "42P08"
258 AmbiguousAlias = "42P09"
259 InvalidColumnReference = "42P10"
260 InvalidColumnDefinition = "42611"
261 InvalidCursorDefinition = "42P11"
262 InvalidDatabaseDefinition = "42P12"
263 InvalidFunctionDefinition = "42P13"
264 InvalidPreparedStatementDefinition = "42P14"
265 InvalidSchemaDefinition = "42P15"
266 InvalidTableDefinition = "42P16"
267 InvalidObjectDefinition = "42P17"
268
269 // Class 44 — WITH CHECK OPTION Violation
270 WithCheckOptionViolation = "44000"
271
272 // Class 53 — Insufficient Resources
273 InsufficientResources = "53000"
274 DiskFull = "53100"
275 OutOfMemory = "53200"
276 TooManyConnections = "53300"
277 ConfigurationLimitExceeded = "53400"
278
279 // Class 54 — Program Limit Exceeded
280 ProgramLimitExceeded = "54000"
281 StatementTooComplex = "54001"
282 TooManyColumns = "54011"
283 TooManyArguments = "54023"
284
285 // Class 55 — Object Not In Prerequisite State
286 ObjectNotInPrerequisiteState = "55000"
287 ObjectInUse = "55006"
288 CantChangeRuntimeParam = "55P02"
289 LockNotAvailable = "55P03"
290 UnsafeNewEnumValueUsage = "55P04"
291
292 // Class 57 — Operator Intervention
293 OperatorIntervention = "57000"
294 QueryCanceled = "57014"
295 AdminShutdown = "57P01"
296 CrashShutdown = "57P02"
297 CannotConnectNow = "57P03"
298 DatabaseDropped = "57P04"
299 IdleSessionTimeout = "57P05"
300
301 // Class 58 — System Error (errors external to PostgreSQL itself)
302 SystemError = "58000"
303 IOError = "58030"
304 UndefinedFile = "58P01"
305 DuplicateFile = "58P02"
306
307 // Class 72 — Snapshot Failure
308 SnapshotTooOld = "72000"
309
310 // Class F0 — Configuration File Error
311 ConfigFileError = "F0000"
312 LockFileExists = "F0001"
313
314 // Class HV — Foreign Data Wrapper Error (SQL/MED)
315 FDWError = "HV000"
316 FDWColumnNameNotFound = "HV005"
317 FDWDynamicParameterValueNeeded = "HV002"
318 FDWFunctionSequenceError = "HV010"
319 FDWInconsistentDescriptorInformation = "HV021"
320 FDWInvalidAttributeValue = "HV024"
321 FDWInvalidColumnName = "HV007"
322 FDWInvalidColumnNumber = "HV008"
323 FDWInvalidDataType = "HV004"
324 FDWInvalidDataTypeDescriptors = "HV006"
325 FDWInvalidDescriptorFieldIdentifier = "HV091"
326 FDWInvalidHandle = "HV00B"
327 FDWInvalidOptionIndex = "HV00C"
328 FDWInvalidOptionName = "HV00D"
329 FDWInvalidStringLengthOrBufferLength = "HV090"
330 FDWInvalidStringFormat = "HV00A"
331 FDWInvalidUseOfNullPointer = "HV009"
332 FDWTooManyHandles = "HV014"
333 FDWOutOfMemory = "HV001"
334 FDWNoSchemas = "HV00P"
335 FDWOptionNameNotFound = "HV00J"
336 FDWReplyHandle = "HV00K"
337 FDWSchemaNotFound = "HV00Q"
338 FDWTableNotFound = "HV00R"
339 FDWUnableToCreateExecution = "HV00L"
340 FDWUnableToCreateReply = "HV00M"
341 FDWUnableToEstablishConnection = "HV00N"
342
343 // Class P0 — PL/pgSQL Error
344 PLpgSQLError = "P0000"
345 RaiseException = "P0001"
346 NoDataFound = "P0002"
347 TooManyRows = "P0003"
348 AssertFailure = "P0004"
349
350 // Class XX — Internal Error
351 InternalError = "XX000"
352 DataCorrupted = "XX001"
353 IndexCorrupted = "XX002"
354 )
355
356 // IsSuccessfulCompletion asserts the error code class is Class 00 — Successful Completion
357 func IsSuccessfulCompletion(code string) bool {
358 switch code {
359 case SuccessfulCompletion:
360 return true
361 }
362 return false
363 }
364
365 // IsWarning asserts the error code class is Class 01 — Warning
366 func IsWarning(code string) bool {
367 switch code {
368 case Warning, DynamicResultSetsReturned, ImplicitZeroBitPadding, NullValueEliminatedInSetFunction, PrivilegeNotGranted, PrivilegeNotRevoked, StringDataRightTruncationWarning, DeprecatedFeature:
369 return true
370 }
371 return false
372 }
373
374 // IsNoData asserts the error code class is Class 02 — No Data (this is also a warning class per the SQL standard)
375 func IsNoData(code string) bool {
376 switch code {
377 case NoData, NoAdditionalDynamicResultSetsReturned:
378 return true
379 }
380 return false
381 }
382
383 // IsSQLStatementNotYetComplete asserts the error code class is Class 03 — SQL Statement Not Yet Complete
384 func IsSQLStatementNotYetComplete(code string) bool {
385 switch code {
386 case SQLStatementNotYetComplete:
387 return true
388 }
389 return false
390 }
391
392 // IsConnectionException asserts the error code class is Class 08 — Connection Exception
393 func IsConnectionException(code string) bool {
394 switch code {
395 case ConnectionException, ConnectionDoesNotExist, ConnectionFailure, SQLClientUnableToEstablishSQLConnection, SQLServerRejectedEstablishmentOfSQLConnection, TransactionResolutionUnknown, ProtocolViolation:
396 return true
397 }
398 return false
399 }
400
401 // IsTriggeredActionException asserts the error code class is Class 09 — Triggered Action Exception
402 func IsTriggeredActionException(code string) bool {
403 switch code {
404 case TriggeredActionException:
405 return true
406 }
407 return false
408 }
409
410 // IsFeatureNotSupported asserts the error code class is Class 0A — Feature Not Supported
411 func IsFeatureNotSupported(code string) bool {
412 switch code {
413 case FeatureNotSupported:
414 return true
415 }
416 return false
417 }
418
419 // IsInvalidTransactionInitiation asserts the error code class is Class 0B — Invalid Transaction Initiation
420 func IsInvalidTransactionInitiation(code string) bool {
421 switch code {
422 case InvalidTransactionInitiation:
423 return true
424 }
425 return false
426 }
427
428 // IsLocatorException asserts the error code class is Class 0F — Locator Exception
429 func IsLocatorException(code string) bool {
430 switch code {
431 case LocatorException, InvalidLocatorSpecification:
432 return true
433 }
434 return false
435 }
436
437 // IsInvalidGrantor asserts the error code class is Class 0L — Invalid Grantor
438 func IsInvalidGrantor(code string) bool {
439 switch code {
440 case InvalidGrantor, InvalidGrantOperation:
441 return true
442 }
443 return false
444 }
445
446 // IsInvalidRoleSpecification asserts the error code class is Class 0P — Invalid Role Specification
447 func IsInvalidRoleSpecification(code string) bool {
448 switch code {
449 case InvalidRoleSpecification:
450 return true
451 }
452 return false
453 }
454
455 // IsDiagnosticsException asserts the error code class is Class 0Z — Diagnostics Exception
456 func IsDiagnosticsException(code string) bool {
457 switch code {
458 case DiagnosticsException, StackedDiagnosticsAccessedWithoutActiveHandler:
459 return true
460 }
461 return false
462 }
463
464 // IsCaseNotFound asserts the error code class is Class 20 — Case Not Found
465 func IsCaseNotFound(code string) bool {
466 switch code {
467 case CaseNotFound:
468 return true
469 }
470 return false
471 }
472
473 // IsCardinalityViolation asserts the error code class is Class 21 — Cardinality Violation
474 func IsCardinalityViolation(code string) bool {
475 switch code {
476 case CardinalityViolation:
477 return true
478 }
479 return false
480 }
481
482 // IsDataException asserts the error code class is Class 22 — Data Exception
483 func IsDataException(code string) bool {
484 switch code {
485 case DataException, ArraySubscriptError, CharacterNotInRepertoire, DatetimeFieldOverflow, DivisionByZero, ErrorInAssignment, EscapeCharacterConflict, IndicatorOverflow, IntervalFieldOverflow, InvalidArgumentForLogarithm, InvalidArgumentForNtileFunction, InvalidArgumentForNthValueFunction, InvalidArgumentForPowerFunction, InvalidArgumentForWidthBucketFunction, InvalidCharacterValueForCast, InvalidDatetimeFormat, InvalidEscapeCharacter, InvalidEscapeOctet, InvalidEscapeSequence, NonstandardUseOfEscapeCharacter, InvalidIndicatorParameterValue, InvalidParameterValue, InvalidPrecedingOrFollowingSize, InvalidRegularExpression, InvalidRowCountInLimitClause, InvalidRowCountInResultOffsetClause, InvalidTablesampleArgument, InvalidTablesampleRepeat, InvalidTimeZoneDisplacementValue, InvalidUseOfEscapeCharacter, MostSpecificTypeMismatch, NullValueNotAllowedDataException, NullValueNoIndicatorParameter, NumericValueOutOfRange, SequenceGeneratorLimitExceeded, StringDataLengthMismatch, StringDataRightTruncationDataException, SubstringError, TrimError, UnterminatedCString, ZeroLengthCharacterString, FloatingPointException, InvalidTextRepresentation, InvalidBinaryRepresentation, BadCopyFileFormat, UntranslatableCharacter, NotAnXMLDocument, InvalidXMLDocument, InvalidXMLContent, InvalidXMLComment, InvalidXMLProcessingInstruction, DuplicateJSONObjectKeyValue, InvalidArgumentForSQLJSONDatetimeFunction, InvalidJSONText, InvalidSQLJSONSubscript, MoreThanOneSQLJSONItem, NoSQLJSONItem, NonNumericSQLJSONItem, NonUniqueKeysInAJSONObject, SingletonSQLJSONItemRequired, SQLJSONArrayNotFound, SQLJSONMemberNotFound, SQLJSONNumberNotFound, SQLJSONObjectNotFound, TooManyJSONArrayElements, TooManyJSONObjectMembers, SQLJSONScalarRequired, SQLJSONItemCannotBeCastToTargetType:
486 return true
487 }
488 return false
489 }
490
491 // IsIntegrityConstraintViolation asserts the error code class is Class 23 — Integrity Constraint Violation
492 func IsIntegrityConstraintViolation(code string) bool {
493 switch code {
494 case IntegrityConstraintViolation, RestrictViolation, NotNullViolation, ForeignKeyViolation, UniqueViolation, CheckViolation, ExclusionViolation:
495 return true
496 }
497 return false
498 }
499
500 // IsInvalidCursorState asserts the error code class is Class 24 — Invalid Cursor State
501 func IsInvalidCursorState(code string) bool {
502 switch code {
503 case InvalidCursorState:
504 return true
505 }
506 return false
507 }
508
509 // IsInvalidTransactionState asserts the error code class is Class 25 — Invalid Transaction State
510 func IsInvalidTransactionState(code string) bool {
511 switch code {
512 case InvalidTransactionState, ActiveSQLTransaction, BranchTransactionAlreadyActive, HeldCursorRequiresSameIsolationLevel, InappropriateAccessModeForBranchTransaction, InappropriateIsolationLevelForBranchTransaction, NoActiveSQLTransactionForBranchTransaction, ReadOnlySQLTransaction, SchemaAndDataStatementMixingNotSupported, NoActiveSQLTransaction, InFailedSQLTransaction, IdleInTransactionSessionTimeout:
513 return true
514 }
515 return false
516 }
517
518 // IsInvalidSQLStatementName asserts the error code class is Class 26 — Invalid SQL Statement Name
519 func IsInvalidSQLStatementName(code string) bool {
520 switch code {
521 case InvalidSQLStatementName:
522 return true
523 }
524 return false
525 }
526
527 // IsTriggeredDataChangeViolation asserts the error code class is Class 27 — Triggered Data Change Violation
528 func IsTriggeredDataChangeViolation(code string) bool {
529 switch code {
530 case TriggeredDataChangeViolation:
531 return true
532 }
533 return false
534 }
535
536 // IsInvalidAuthorizationSpecification asserts the error code class is Class 28 — Invalid Authorization Specification
537 func IsInvalidAuthorizationSpecification(code string) bool {
538 switch code {
539 case InvalidAuthorizationSpecification, InvalidPassword:
540 return true
541 }
542 return false
543 }
544
545 // IsDependentPrivilegeDescriptorsStillExist asserts the error code class is Class 2B — Dependent Privilege Descriptors Still Exist
546 func IsDependentPrivilegeDescriptorsStillExist(code string) bool {
547 switch code {
548 case DependentPrivilegeDescriptorsStillExist, DependentObjectsStillExist:
549 return true
550 }
551 return false
552 }
553
554 // IsInvalidTransactionTermination asserts the error code class is Class 2D — Invalid Transaction Termination
555 func IsInvalidTransactionTermination(code string) bool {
556 switch code {
557 case InvalidTransactionTermination:
558 return true
559 }
560 return false
561 }
562
563 // IsSQLRoutineException asserts the error code class is Class 2F — SQL Routine Exception
564 func IsSQLRoutineException(code string) bool {
565 switch code {
566 case SQLRoutineException, FunctionExecutedNoReturnStatement, ModifyingSQLDataNotPermittedSQLRoutineException, ProhibitedSQLStatementAttemptedSQLRoutineException, ReadingSQLDataNotPermittedSQLRoutineException:
567 return true
568 }
569 return false
570 }
571
572 // IsInvalidCursorName asserts the error code class is Class 34 — Invalid Cursor Name
573 func IsInvalidCursorName(code string) bool {
574 switch code {
575 case InvalidCursorName:
576 return true
577 }
578 return false
579 }
580
581 // IsExternalRoutineException asserts the error code class is Class 38 — External Routine Exception
582 func IsExternalRoutineException(code string) bool {
583 switch code {
584 case ExternalRoutineException, ContainingSQLNotPermitted, ModifyingSQLDataNotPermittedExternalRoutineException, ProhibitedSQLStatementAttemptedExternalRoutineException, ReadingSQLDataNotPermittedExternalRoutineException:
585 return true
586 }
587 return false
588 }
589
590 // IsExternalRoutineInvocationException asserts the error code class is Class 39 — External Routine Invocation Exception
591 func IsExternalRoutineInvocationException(code string) bool {
592 switch code {
593 case ExternalRoutineInvocationException, InvalidSQLstateReturned, NullValueNotAllowedExternalRoutineInvocationException, TriggerProtocolViolated, SRFProtocolViolated, EventTriggerProtocolViolated:
594 return true
595 }
596 return false
597 }
598
599 // IsSavepointException asserts the error code class is Class 3B — Savepoint Exception
600 func IsSavepointException(code string) bool {
601 switch code {
602 case SavepointException, InvalidSavepointSpecification:
603 return true
604 }
605 return false
606 }
607
608 // IsInvalidCatalogName asserts the error code class is Class 3D — Invalid Catalog Name
609 func IsInvalidCatalogName(code string) bool {
610 switch code {
611 case InvalidCatalogName:
612 return true
613 }
614 return false
615 }
616
617 // IsInvalidSchemaName asserts the error code class is Class 3F — Invalid Schema Name
618 func IsInvalidSchemaName(code string) bool {
619 switch code {
620 case InvalidSchemaName:
621 return true
622 }
623 return false
624 }
625
626 // IsTransactionRollback asserts the error code class is Class 40 — Transaction Rollback
627 func IsTransactionRollback(code string) bool {
628 switch code {
629 case TransactionRollback, TransactionIntegrityConstraintViolation, SerializationFailure, StatementCompletionUnknown, DeadlockDetected:
630 return true
631 }
632 return false
633 }
634
635 // IsSyntaxErrororAccessRuleViolation asserts the error code class is Class 42 — Syntax Error or Access Rule Violation
636 func IsSyntaxErrororAccessRuleViolation(code string) bool {
637 switch code {
638 case SyntaxErrorOrAccessRuleViolation, SyntaxError, InsufficientPrivilege, CannotCoerce, GroupingError, WindowingError, InvalidRecursion, InvalidForeignKey, InvalidName, NameTooLong, ReservedName, DatatypeMismatch, IndeterminateDatatype, CollationMismatch, IndeterminateCollation, WrongObjectType, GeneratedAlways, UndefinedColumn, UndefinedFunction, UndefinedTable, UndefinedParameter, UndefinedObject, DuplicateColumn, DuplicateCursor, DuplicateDatabase, DuplicateFunction, DuplicatePreparedStatement, DuplicateSchema, DuplicateTable, DuplicateAlias, DuplicateObject, AmbiguousColumn, AmbiguousFunction, AmbiguousParameter, AmbiguousAlias, InvalidColumnReference, InvalidColumnDefinition, InvalidCursorDefinition, InvalidDatabaseDefinition, InvalidFunctionDefinition, InvalidPreparedStatementDefinition, InvalidSchemaDefinition, InvalidTableDefinition, InvalidObjectDefinition:
639 return true
640 }
641 return false
642 }
643
644 // IsWithCheckOptionViolation asserts the error code class is Class 44 — WITH CHECK OPTION Violation
645 func IsWithCheckOptionViolation(code string) bool {
646 switch code {
647 case WithCheckOptionViolation:
648 return true
649 }
650 return false
651 }
652
653 // IsInsufficientResources asserts the error code class is Class 53 — Insufficient Resources
654 func IsInsufficientResources(code string) bool {
655 switch code {
656 case InsufficientResources, DiskFull, OutOfMemory, TooManyConnections, ConfigurationLimitExceeded:
657 return true
658 }
659 return false
660 }
661
662 // IsProgramLimitExceeded asserts the error code class is Class 54 — Program Limit Exceeded
663 func IsProgramLimitExceeded(code string) bool {
664 switch code {
665 case ProgramLimitExceeded, StatementTooComplex, TooManyColumns, TooManyArguments:
666 return true
667 }
668 return false
669 }
670
671 // IsObjectNotInPrerequisiteState asserts the error code class is Class 55 — Object Not In Prerequisite State
672 func IsObjectNotInPrerequisiteState(code string) bool {
673 switch code {
674 case ObjectNotInPrerequisiteState, ObjectInUse, CantChangeRuntimeParam, LockNotAvailable, UnsafeNewEnumValueUsage:
675 return true
676 }
677 return false
678 }
679
680 // IsOperatorIntervention asserts the error code class is Class 57 — Operator Intervention
681 func IsOperatorIntervention(code string) bool {
682 switch code {
683 case OperatorIntervention, QueryCanceled, AdminShutdown, CrashShutdown, CannotConnectNow, DatabaseDropped, IdleSessionTimeout:
684 return true
685 }
686 return false
687 }
688
689 // IsSystemError asserts the error code class is Class 58 — System Error (errors external to PostgreSQL itself)
690 func IsSystemError(code string) bool {
691 switch code {
692 case SystemError, IOError, UndefinedFile, DuplicateFile:
693 return true
694 }
695 return false
696 }
697
698 // IsSnapshotFailure asserts the error code class is Class 72 — Snapshot Failure
699 func IsSnapshotFailure(code string) bool {
700 switch code {
701 case SnapshotTooOld:
702 return true
703 }
704 return false
705 }
706
707 // IsConfigurationFileError asserts the error code class is Class F0 — Configuration File Error
708 func IsConfigurationFileError(code string) bool {
709 switch code {
710 case ConfigFileError, LockFileExists:
711 return true
712 }
713 return false
714 }
715
716 // IsForeignDataWrapperError asserts the error code class is Class HV — Foreign Data Wrapper Error (SQL/MED)
717 func IsForeignDataWrapperError(code string) bool {
718 switch code {
719 case FDWError, FDWColumnNameNotFound, FDWDynamicParameterValueNeeded, FDWFunctionSequenceError, FDWInconsistentDescriptorInformation, FDWInvalidAttributeValue, FDWInvalidColumnName, FDWInvalidColumnNumber, FDWInvalidDataType, FDWInvalidDataTypeDescriptors, FDWInvalidDescriptorFieldIdentifier, FDWInvalidHandle, FDWInvalidOptionIndex, FDWInvalidOptionName, FDWInvalidStringLengthOrBufferLength, FDWInvalidStringFormat, FDWInvalidUseOfNullPointer, FDWTooManyHandles, FDWOutOfMemory, FDWNoSchemas, FDWOptionNameNotFound, FDWReplyHandle, FDWSchemaNotFound, FDWTableNotFound, FDWUnableToCreateExecution, FDWUnableToCreateReply, FDWUnableToEstablishConnection:
720 return true
721 }
722 return false
723 }
724
725 // IsPLpgSQLError asserts the error code class is Class P0 — PL/pgSQL Error
726 func IsPLpgSQLError(code string) bool {
727 switch code {
728 case PLpgSQLError, RaiseException, NoDataFound, TooManyRows, AssertFailure:
729 return true
730 }
731 return false
732 }
733
734 // IsInternalError asserts the error code class is Class XX — Internal Error
735 func IsInternalError(code string) bool {
736 switch code {
737 case InternalError, DataCorrupted, IndexCorrupted:
738 return true
739 }
740 return false
741 }
742
743 // Name returns the string name for a given PostgreSQL error code.
744 // Returns an empty string if the error code is not recognized.
745 func Name(code string) string {
746 switch code {
747 case "00000":
748 return "SuccessfulCompletion"
749 case "01000":
750 return "Warning"
751 case "0100C":
752 return "DynamicResultSetsReturned"
753 case "01008":
754 return "ImplicitZeroBitPadding"
755 case "01003":
756 return "NullValueEliminatedInSetFunction"
757 case "01007":
758 return "PrivilegeNotGranted"
759 case "01006":
760 return "PrivilegeNotRevoked"
761 case "01004":
762 return "StringDataRightTruncationWarning"
763 case "01P01":
764 return "DeprecatedFeature"
765 case "02000":
766 return "NoData"
767 case "02001":
768 return "NoAdditionalDynamicResultSetsReturned"
769 case "03000":
770 return "SQLStatementNotYetComplete"
771 case "08000":
772 return "ConnectionException"
773 case "08003":
774 return "ConnectionDoesNotExist"
775 case "08006":
776 return "ConnectionFailure"
777 case "08001":
778 return "SQLClientUnableToEstablishSQLConnection"
779 case "08004":
780 return "SQLServerRejectedEstablishmentOfSQLConnection"
781 case "08007":
782 return "TransactionResolutionUnknown"
783 case "08P01":
784 return "ProtocolViolation"
785 case "09000":
786 return "TriggeredActionException"
787 case "0A000":
788 return "FeatureNotSupported"
789 case "0B000":
790 return "InvalidTransactionInitiation"
791 case "0F000":
792 return "LocatorException"
793 case "0F001":
794 return "InvalidLocatorSpecification"
795 case "0L000":
796 return "InvalidGrantor"
797 case "0LP01":
798 return "InvalidGrantOperation"
799 case "0P000":
800 return "InvalidRoleSpecification"
801 case "0Z000":
802 return "DiagnosticsException"
803 case "0Z002":
804 return "StackedDiagnosticsAccessedWithoutActiveHandler"
805 case "20000":
806 return "CaseNotFound"
807 case "21000":
808 return "CardinalityViolation"
809 case "22000":
810 return "DataException"
811 case "2202E":
812 return "ArraySubscriptError"
813 case "22021":
814 return "CharacterNotInRepertoire"
815 case "22008":
816 return "DatetimeFieldOverflow"
817 case "22012":
818 return "DivisionByZero"
819 case "22005":
820 return "ErrorInAssignment"
821 case "2200B":
822 return "EscapeCharacterConflict"
823 case "22022":
824 return "IndicatorOverflow"
825 case "22015":
826 return "IntervalFieldOverflow"
827 case "2201E":
828 return "InvalidArgumentForLogarithm"
829 case "22014":
830 return "InvalidArgumentForNtileFunction"
831 case "22016":
832 return "InvalidArgumentForNthValueFunction"
833 case "2201F":
834 return "InvalidArgumentForPowerFunction"
835 case "2201G":
836 return "InvalidArgumentForWidthBucketFunction"
837 case "22018":
838 return "InvalidCharacterValueForCast"
839 case "22007":
840 return "InvalidDatetimeFormat"
841 case "22019":
842 return "InvalidEscapeCharacter"
843 case "2200D":
844 return "InvalidEscapeOctet"
845 case "22025":
846 return "InvalidEscapeSequence"
847 case "22P06":
848 return "NonstandardUseOfEscapeCharacter"
849 case "22010":
850 return "InvalidIndicatorParameterValue"
851 case "22023":
852 return "InvalidParameterValue"
853 case "22013":
854 return "InvalidPrecedingOrFollowingSize"
855 case "2201B":
856 return "InvalidRegularExpression"
857 case "2201W":
858 return "InvalidRowCountInLimitClause"
859 case "2201X":
860 return "InvalidRowCountInResultOffsetClause"
861 case "2202H":
862 return "InvalidTablesampleArgument"
863 case "2202G":
864 return "InvalidTablesampleRepeat"
865 case "22009":
866 return "InvalidTimeZoneDisplacementValue"
867 case "2200C":
868 return "InvalidUseOfEscapeCharacter"
869 case "2200G":
870 return "MostSpecificTypeMismatch"
871 case "22004":
872 return "NullValueNotAllowedDataException"
873 case "22002":
874 return "NullValueNoIndicatorParameter"
875 case "22003":
876 return "NumericValueOutOfRange"
877 case "2200H":
878 return "SequenceGeneratorLimitExceeded"
879 case "22026":
880 return "StringDataLengthMismatch"
881 case "22001":
882 return "StringDataRightTruncationDataException"
883 case "22011":
884 return "SubstringError"
885 case "22027":
886 return "TrimError"
887 case "22024":
888 return "UnterminatedCString"
889 case "2200F":
890 return "ZeroLengthCharacterString"
891 case "22P01":
892 return "FloatingPointException"
893 case "22P02":
894 return "InvalidTextRepresentation"
895 case "22P03":
896 return "InvalidBinaryRepresentation"
897 case "22P04":
898 return "BadCopyFileFormat"
899 case "22P05":
900 return "UntranslatableCharacter"
901 case "2200L":
902 return "NotAnXMLDocument"
903 case "2200M":
904 return "InvalidXMLDocument"
905 case "2200N":
906 return "InvalidXMLContent"
907 case "2200S":
908 return "InvalidXMLComment"
909 case "2200T":
910 return "InvalidXMLProcessingInstruction"
911 case "22030":
912 return "DuplicateJSONObjectKeyValue"
913 case "22031":
914 return "InvalidArgumentForSQLJSONDatetimeFunction"
915 case "22032":
916 return "InvalidJSONText"
917 case "22033":
918 return "InvalidSQLJSONSubscript"
919 case "22034":
920 return "MoreThanOneSQLJSONItem"
921 case "22035":
922 return "NoSQLJSONItem"
923 case "22036":
924 return "NonNumericSQLJSONItem"
925 case "22037":
926 return "NonUniqueKeysInAJSONObject"
927 case "22038":
928 return "SingletonSQLJSONItemRequired"
929 case "22039":
930 return "SQLJSONArrayNotFound"
931 case "2203A":
932 return "SQLJSONMemberNotFound"
933 case "2203B":
934 return "SQLJSONNumberNotFound"
935 case "2203C":
936 return "SQLJSONObjectNotFound"
937 case "2203D":
938 return "TooManyJSONArrayElements"
939 case "2203E":
940 return "TooManyJSONObjectMembers"
941 case "2203F":
942 return "SQLJSONScalarRequired"
943 case "2203G":
944 return "SQLJSONItemCannotBeCastToTargetType"
945 case "23000":
946 return "IntegrityConstraintViolation"
947 case "23001":
948 return "RestrictViolation"
949 case "23502":
950 return "NotNullViolation"
951 case "23503":
952 return "ForeignKeyViolation"
953 case "23505":
954 return "UniqueViolation"
955 case "23514":
956 return "CheckViolation"
957 case "23P01":
958 return "ExclusionViolation"
959 case "24000":
960 return "InvalidCursorState"
961 case "25000":
962 return "InvalidTransactionState"
963 case "25001":
964 return "ActiveSQLTransaction"
965 case "25002":
966 return "BranchTransactionAlreadyActive"
967 case "25008":
968 return "HeldCursorRequiresSameIsolationLevel"
969 case "25003":
970 return "InappropriateAccessModeForBranchTransaction"
971 case "25004":
972 return "InappropriateIsolationLevelForBranchTransaction"
973 case "25005":
974 return "NoActiveSQLTransactionForBranchTransaction"
975 case "25006":
976 return "ReadOnlySQLTransaction"
977 case "25007":
978 return "SchemaAndDataStatementMixingNotSupported"
979 case "25P01":
980 return "NoActiveSQLTransaction"
981 case "25P02":
982 return "InFailedSQLTransaction"
983 case "25P03":
984 return "IdleInTransactionSessionTimeout"
985 case "26000":
986 return "InvalidSQLStatementName"
987 case "27000":
988 return "TriggeredDataChangeViolation"
989 case "28000":
990 return "InvalidAuthorizationSpecification"
991 case "28P01":
992 return "InvalidPassword"
993 case "2B000":
994 return "DependentPrivilegeDescriptorsStillExist"
995 case "2BP01":
996 return "DependentObjectsStillExist"
997 case "2D000":
998 return "InvalidTransactionTermination"
999 case "2F000":
1000 return "SQLRoutineException"
1001 case "2F005":
1002 return "FunctionExecutedNoReturnStatement"
1003 case "2F002":
1004 return "ModifyingSQLDataNotPermittedSQLRoutineException"
1005 case "2F003":
1006 return "ProhibitedSQLStatementAttemptedSQLRoutineException"
1007 case "2F004":
1008 return "ReadingSQLDataNotPermittedSQLRoutineException"
1009 case "34000":
1010 return "InvalidCursorName"
1011 case "38000":
1012 return "ExternalRoutineException"
1013 case "38001":
1014 return "ContainingSQLNotPermitted"
1015 case "38002":
1016 return "ModifyingSQLDataNotPermittedExternalRoutineException"
1017 case "38003":
1018 return "ProhibitedSQLStatementAttemptedExternalRoutineException"
1019 case "38004":
1020 return "ReadingSQLDataNotPermittedExternalRoutineException"
1021 case "39000":
1022 return "ExternalRoutineInvocationException"
1023 case "39001":
1024 return "InvalidSQLstateReturned"
1025 case "39004":
1026 return "NullValueNotAllowedExternalRoutineInvocationException"
1027 case "39P01":
1028 return "TriggerProtocolViolated"
1029 case "39P02":
1030 return "SRFProtocolViolated"
1031 case "39P03":
1032 return "EventTriggerProtocolViolated"
1033 case "3B000":
1034 return "SavepointException"
1035 case "3B001":
1036 return "InvalidSavepointSpecification"
1037 case "3D000":
1038 return "InvalidCatalogName"
1039 case "3F000":
1040 return "InvalidSchemaName"
1041 case "40000":
1042 return "TransactionRollback"
1043 case "40002":
1044 return "TransactionIntegrityConstraintViolation"
1045 case "40001":
1046 return "SerializationFailure"
1047 case "40003":
1048 return "StatementCompletionUnknown"
1049 case "40P01":
1050 return "DeadlockDetected"
1051 case "42000":
1052 return "SyntaxErrorOrAccessRuleViolation"
1053 case "42601":
1054 return "SyntaxError"
1055 case "42501":
1056 return "InsufficientPrivilege"
1057 case "42846":
1058 return "CannotCoerce"
1059 case "42803":
1060 return "GroupingError"
1061 case "42P20":
1062 return "WindowingError"
1063 case "42P19":
1064 return "InvalidRecursion"
1065 case "42830":
1066 return "InvalidForeignKey"
1067 case "42602":
1068 return "InvalidName"
1069 case "42622":
1070 return "NameTooLong"
1071 case "42939":
1072 return "ReservedName"
1073 case "42804":
1074 return "DatatypeMismatch"
1075 case "42P18":
1076 return "IndeterminateDatatype"
1077 case "42P21":
1078 return "CollationMismatch"
1079 case "42P22":
1080 return "IndeterminateCollation"
1081 case "42809":
1082 return "WrongObjectType"
1083 case "428C9":
1084 return "GeneratedAlways"
1085 case "42703":
1086 return "UndefinedColumn"
1087 case "42883":
1088 return "UndefinedFunction"
1089 case "42P01":
1090 return "UndefinedTable"
1091 case "42P02":
1092 return "UndefinedParameter"
1093 case "42704":
1094 return "UndefinedObject"
1095 case "42701":
1096 return "DuplicateColumn"
1097 case "42P03":
1098 return "DuplicateCursor"
1099 case "42P04":
1100 return "DuplicateDatabase"
1101 case "42723":
1102 return "DuplicateFunction"
1103 case "42P05":
1104 return "DuplicatePreparedStatement"
1105 case "42P06":
1106 return "DuplicateSchema"
1107 case "42P07":
1108 return "DuplicateTable"
1109 case "42712":
1110 return "DuplicateAlias"
1111 case "42710":
1112 return "DuplicateObject"
1113 case "42702":
1114 return "AmbiguousColumn"
1115 case "42725":
1116 return "AmbiguousFunction"
1117 case "42P08":
1118 return "AmbiguousParameter"
1119 case "42P09":
1120 return "AmbiguousAlias"
1121 case "42P10":
1122 return "InvalidColumnReference"
1123 case "42611":
1124 return "InvalidColumnDefinition"
1125 case "42P11":
1126 return "InvalidCursorDefinition"
1127 case "42P12":
1128 return "InvalidDatabaseDefinition"
1129 case "42P13":
1130 return "InvalidFunctionDefinition"
1131 case "42P14":
1132 return "InvalidPreparedStatementDefinition"
1133 case "42P15":
1134 return "InvalidSchemaDefinition"
1135 case "42P16":
1136 return "InvalidTableDefinition"
1137 case "42P17":
1138 return "InvalidObjectDefinition"
1139 case "44000":
1140 return "WithCheckOptionViolation"
1141 case "53000":
1142 return "InsufficientResources"
1143 case "53100":
1144 return "DiskFull"
1145 case "53200":
1146 return "OutOfMemory"
1147 case "53300":
1148 return "TooManyConnections"
1149 case "53400":
1150 return "ConfigurationLimitExceeded"
1151 case "54000":
1152 return "ProgramLimitExceeded"
1153 case "54001":
1154 return "StatementTooComplex"
1155 case "54011":
1156 return "TooManyColumns"
1157 case "54023":
1158 return "TooManyArguments"
1159 case "55000":
1160 return "ObjectNotInPrerequisiteState"
1161 case "55006":
1162 return "ObjectInUse"
1163 case "55P02":
1164 return "CantChangeRuntimeParam"
1165 case "55P03":
1166 return "LockNotAvailable"
1167 case "55P04":
1168 return "UnsafeNewEnumValueUsage"
1169 case "57000":
1170 return "OperatorIntervention"
1171 case "57014":
1172 return "QueryCanceled"
1173 case "57P01":
1174 return "AdminShutdown"
1175 case "57P02":
1176 return "CrashShutdown"
1177 case "57P03":
1178 return "CannotConnectNow"
1179 case "57P04":
1180 return "DatabaseDropped"
1181 case "57P05":
1182 return "IdleSessionTimeout"
1183 case "58000":
1184 return "SystemError"
1185 case "58030":
1186 return "IOError"
1187 case "58P01":
1188 return "UndefinedFile"
1189 case "58P02":
1190 return "DuplicateFile"
1191 case "72000":
1192 return "SnapshotTooOld"
1193 case "F0000":
1194 return "ConfigFileError"
1195 case "F0001":
1196 return "LockFileExists"
1197 case "HV000":
1198 return "FDWError"
1199 case "HV005":
1200 return "FDWColumnNameNotFound"
1201 case "HV002":
1202 return "FDWDynamicParameterValueNeeded"
1203 case "HV010":
1204 return "FDWFunctionSequenceError"
1205 case "HV021":
1206 return "FDWInconsistentDescriptorInformation"
1207 case "HV024":
1208 return "FDWInvalidAttributeValue"
1209 case "HV007":
1210 return "FDWInvalidColumnName"
1211 case "HV008":
1212 return "FDWInvalidColumnNumber"
1213 case "HV004":
1214 return "FDWInvalidDataType"
1215 case "HV006":
1216 return "FDWInvalidDataTypeDescriptors"
1217 case "HV091":
1218 return "FDWInvalidDescriptorFieldIdentifier"
1219 case "HV00B":
1220 return "FDWInvalidHandle"
1221 case "HV00C":
1222 return "FDWInvalidOptionIndex"
1223 case "HV00D":
1224 return "FDWInvalidOptionName"
1225 case "HV090":
1226 return "FDWInvalidStringLengthOrBufferLength"
1227 case "HV00A":
1228 return "FDWInvalidStringFormat"
1229 case "HV009":
1230 return "FDWInvalidUseOfNullPointer"
1231 case "HV014":
1232 return "FDWTooManyHandles"
1233 case "HV001":
1234 return "FDWOutOfMemory"
1235 case "HV00P":
1236 return "FDWNoSchemas"
1237 case "HV00J":
1238 return "FDWOptionNameNotFound"
1239 case "HV00K":
1240 return "FDWReplyHandle"
1241 case "HV00Q":
1242 return "FDWSchemaNotFound"
1243 case "HV00R":
1244 return "FDWTableNotFound"
1245 case "HV00L":
1246 return "FDWUnableToCreateExecution"
1247 case "HV00M":
1248 return "FDWUnableToCreateReply"
1249 case "HV00N":
1250 return "FDWUnableToEstablishConnection"
1251 case "P0000":
1252 return "PLpgSQLError"
1253 case "P0001":
1254 return "RaiseException"
1255 case "P0002":
1256 return "NoDataFound"
1257 case "P0003":
1258 return "TooManyRows"
1259 case "P0004":
1260 return "AssertFailure"
1261 case "XX000":
1262 return "InternalError"
1263 case "XX001":
1264 return "DataCorrupted"
1265 case "XX002":
1266 return "IndexCorrupted"
1267 }
1268 return ""
1269 }