github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/pgwire/pgcode/codes.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package pgcode 12 13 import "regexp" 14 15 // Code is a wrapper around a string to ensure that pgcodes are used in 16 // different pgerror functions by avoiding accidental string input. 17 type Code struct { 18 code string 19 } 20 21 // MakeCode converts a string into a Code. 22 func MakeCode(s string) Code { 23 return Code{code: s} 24 } 25 26 // String returns the underlying pgcode string. 27 func (c Code) String() string { 28 return c.code 29 } 30 31 // PG error codes from: http://www.postgresql.org/docs/9.5/static/errcodes-appendix.html. 32 // Specifically, errcodes.txt is copied from from Postgres' src/backend/utils/errcodes.txt. 33 // 34 // The error definitions were generated using the generate.sh script, 35 // with a bit of manual tweaking performed afterwards. 36 var ( 37 // Section: Class 00 - Successful Completion 38 SuccessfulCompletion = MakeCode("00000") 39 // Section: Class 01 - Warning 40 Warning = MakeCode("01000") 41 WarningDynamicResultSetsReturned = MakeCode("0100C") 42 WarningImplicitZeroBitPadding = MakeCode("01008") 43 WarningNullValueEliminatedInSetFunction = MakeCode("01003") 44 WarningPrivilegeNotGranted = MakeCode("01007") 45 WarningPrivilegeNotRevoked = MakeCode("01006") 46 WarningStringDataRightTruncation = MakeCode("01004") 47 WarningDeprecatedFeature = MakeCode("01P01") 48 // Section: Class 02 - No Data (this is also a warning class per the SQL standard) 49 NoData = MakeCode("02000") 50 NoAdditionalDynamicResultSetsReturned = MakeCode("02001") 51 // Section: Class 03 - SQL Statement Not Yet Complete 52 SQLStatementNotYetComplete = MakeCode("03000") 53 // Section: Class 08 - Connection Exception 54 ConnectionException = MakeCode("08000") 55 ConnectionDoesNotExist = MakeCode("08003") 56 ConnectionFailure = MakeCode("08006") 57 SQLclientUnableToEstablishSQLconnection = MakeCode("08001") 58 SQLserverRejectedEstablishmentOfSQLconnection = MakeCode("08004") 59 TransactionResolutionUnknown = MakeCode("08007") 60 ProtocolViolation = MakeCode("08P01") 61 // Section: Class 09 - Triggered Action Exception 62 TriggeredActionException = MakeCode("09000") 63 // Section: Class 0A - Feature Not Supported 64 FeatureNotSupported = MakeCode("0A000") 65 // Section: Class 0B - Invalid Transaction Initiation 66 InvalidTransactionInitiation = MakeCode("0B000") 67 // Section: Class 0F - Locator Exception 68 LocatorException = MakeCode("0F000") 69 InvalidLocatorSpecification = MakeCode("0F001") 70 // Section: Class 0L - Invalid Grantor 71 InvalidGrantor = MakeCode("0L000") 72 InvalidGrantOperation = MakeCode("0LP01") 73 // Section: Class 0P - Invalid Role Specification 74 InvalidRoleSpecification = MakeCode("0P000") 75 // Section: Class 0Z - Diagnostics Exception 76 DiagnosticsException = MakeCode("0Z000") 77 StackedDiagnosticsAccessedWithoutActiveHandler = MakeCode("0Z002") 78 // Section: Class 20 - Case Not Found 79 CaseNotFound = MakeCode("20000") 80 // Section: Class 21 - Cardinality Violation 81 CardinalityViolation = MakeCode("21000") 82 // Section: Class 22 - Data Exception 83 DataException = MakeCode("22000") 84 ArraySubscript = MakeCode("2202E") 85 CharacterNotInRepertoire = MakeCode("22021") 86 DatetimeFieldOverflow = MakeCode("22008") 87 DivisionByZero = MakeCode("22012") 88 InvalidWindowFrameOffset = MakeCode("22013") 89 ErrorInAssignment = MakeCode("22005") 90 EscapeCharacterConflict = MakeCode("2200B") 91 IndicatorOverflow = MakeCode("22022") 92 IntervalFieldOverflow = MakeCode("22015") 93 InvalidArgumentForLogarithm = MakeCode("2201E") 94 InvalidArgumentForNtileFunction = MakeCode("22014") 95 InvalidArgumentForNthValueFunction = MakeCode("22016") 96 InvalidArgumentForPowerFunction = MakeCode("2201F") 97 InvalidArgumentForWidthBucketFunction = MakeCode("2201G") 98 InvalidCharacterValueForCast = MakeCode("22018") 99 InvalidDatetimeFormat = MakeCode("22007") 100 InvalidEscapeCharacter = MakeCode("22019") 101 InvalidEscapeOctet = MakeCode("2200D") 102 InvalidEscapeSequence = MakeCode("22025") 103 NonstandardUseOfEscapeCharacter = MakeCode("22P06") 104 InvalidIndicatorParameterValue = MakeCode("22010") 105 InvalidParameterValue = MakeCode("22023") 106 InvalidRegularExpression = MakeCode("2201B") 107 InvalidRowCountInLimitClause = MakeCode("2201W") 108 InvalidRowCountInResultOffsetClause = MakeCode("2201X") 109 InvalidTimeZoneDisplacementValue = MakeCode("22009") 110 InvalidUseOfEscapeCharacter = MakeCode("2200C") 111 MostSpecificTypeMismatch = MakeCode("2200G") 112 NullValueNotAllowed = MakeCode("22004") 113 NullValueNoIndicatorParameter = MakeCode("22002") 114 NumericValueOutOfRange = MakeCode("22003") 115 SequenceGeneratorLimitExceeded = MakeCode("2200H") 116 StringDataLengthMismatch = MakeCode("22026") 117 StringDataRightTruncation = MakeCode("22001") 118 Substring = MakeCode("22011") 119 Trim = MakeCode("22027") 120 UnterminatedCString = MakeCode("22024") 121 ZeroLengthCharacterString = MakeCode("2200F") 122 FloatingPointException = MakeCode("22P01") 123 InvalidTextRepresentation = MakeCode("22P02") 124 InvalidBinaryRepresentation = MakeCode("22P03") 125 BadCopyFileFormat = MakeCode("22P04") 126 UntranslatableCharacter = MakeCode("22P05") 127 NotAnXMLDocument = MakeCode("2200L") 128 InvalidXMLDocument = MakeCode("2200M") 129 InvalidXMLContent = MakeCode("2200N") 130 InvalidXMLComment = MakeCode("2200S") 131 InvalidXMLProcessingInstruction = MakeCode("2200T") 132 // Section: Class 23 - Integrity Constraint Violation 133 IntegrityConstraintViolation = MakeCode("23000") 134 RestrictViolation = MakeCode("23001") 135 NotNullViolation = MakeCode("23502") 136 ForeignKeyViolation = MakeCode("23503") 137 UniqueViolation = MakeCode("23505") 138 CheckViolation = MakeCode("23514") 139 ExclusionViolation = MakeCode("23P01") 140 // Section: Class 24 - Invalid Cursor State 141 InvalidCursorState = MakeCode("24000") 142 // Section: Class 25 - Invalid Transaction State 143 InvalidTransactionState = MakeCode("25000") 144 ActiveSQLTransaction = MakeCode("25001") 145 BranchTransactionAlreadyActive = MakeCode("25002") 146 HeldCursorRequiresSameIsolationLevel = MakeCode("25008") 147 InappropriateAccessModeForBranchTransaction = MakeCode("25003") 148 InappropriateIsolationLevelForBranchTransaction = MakeCode("25004") 149 NoActiveSQLTransactionForBranchTransaction = MakeCode("25005") 150 ReadOnlySQLTransaction = MakeCode("25006") 151 SchemaAndDataStatementMixingNotSupported = MakeCode("25007") 152 NoActiveSQLTransaction = MakeCode("25P01") 153 InFailedSQLTransaction = MakeCode("25P02") 154 // Section: Class 26 - Invalid SQL Statement Name 155 InvalidSQLStatementName = MakeCode("26000") 156 // Section: Class 27 - Triggered Data Change Violation 157 TriggeredDataChangeViolation = MakeCode("27000") 158 // Section: Class 28 - Invalid Authorization Specification 159 InvalidAuthorizationSpecification = MakeCode("28000") 160 InvalidPassword = MakeCode("28P01") 161 // Section: Class 2B - Dependent Privilege Descriptors Still Exist 162 DependentPrivilegeDescriptorsStillExist = MakeCode("2B000") 163 DependentObjectsStillExist = MakeCode("2BP01") 164 // Section: Class 2D - Invalid Transaction Termination 165 InvalidTransactionTermination = MakeCode("2D000") 166 // Section: Class 2F - SQL Routine Exception 167 RoutineExceptionFunctionExecutedNoReturnStatement = MakeCode("2F005") 168 RoutineExceptionModifyingSQLDataNotPermitted = MakeCode("2F002") 169 RoutineExceptionProhibitedSQLStatementAttempted = MakeCode("2F003") 170 RoutineExceptionReadingSQLDataNotPermitted = MakeCode("2F004") 171 // Section: Class 34 - Invalid Cursor Name 172 InvalidCursorName = MakeCode("34000") 173 // Section: Class 38 - External Routine Exception 174 ExternalRoutineException = MakeCode("38000") 175 ExternalRoutineContainingSQLNotPermitted = MakeCode("38001") 176 ExternalRoutineModifyingSQLDataNotPermitted = MakeCode("38002") 177 ExternalRoutineProhibitedSQLStatementAttempted = MakeCode("38003") 178 ExternalRoutineReadingSQLDataNotPermitted = MakeCode("38004") 179 // Section: Class 39 - External Routine Invocation Exception 180 ExternalRoutineInvocationException = MakeCode("39000") 181 ExternalRoutineInvalidSQLstateReturned = MakeCode("39001") 182 ExternalRoutineNullValueNotAllowed = MakeCode("39004") 183 ExternalRoutineTriggerProtocolViolated = MakeCode("39P01") 184 ExternalRoutineSrfProtocolViolated = MakeCode("39P02") 185 // Section: Class 3B - Savepoint Exception 186 SavepointException = MakeCode("3B000") 187 InvalidSavepointSpecification = MakeCode("3B001") 188 // Section: Class 3D - Invalid Catalog Name 189 InvalidCatalogName = MakeCode("3D000") 190 // Section: Class 3F - Invalid Schema Name 191 InvalidSchemaName = MakeCode("3F000") 192 // Section: Class 40 - Transaction Rollback 193 TransactionRollback = MakeCode("40000") 194 TransactionIntegrityConstraintViolation = MakeCode("40002") 195 SerializationFailure = MakeCode("40001") 196 StatementCompletionUnknown = MakeCode("40003") 197 DeadlockDetected = MakeCode("40P01") 198 // Section: Class 42 - Syntax Error or Access Rule Violation 199 SyntaxErrorOrAccessRuleViolation = MakeCode("42000") 200 Syntax = MakeCode("42601") 201 InsufficientPrivilege = MakeCode("42501") 202 CannotCoerce = MakeCode("42846") 203 Grouping = MakeCode("42803") 204 Windowing = MakeCode("42P20") 205 InvalidRecursion = MakeCode("42P19") 206 InvalidForeignKey = MakeCode("42830") 207 InvalidName = MakeCode("42602") 208 NameTooLong = MakeCode("42622") 209 ReservedName = MakeCode("42939") 210 DatatypeMismatch = MakeCode("42804") 211 IndeterminateDatatype = MakeCode("42P18") 212 CollationMismatch = MakeCode("42P21") 213 IndeterminateCollation = MakeCode("42P22") 214 WrongObjectType = MakeCode("42809") 215 GeneratedAlways = MakeCode("428C9") 216 UndefinedColumn = MakeCode("42703") 217 UndefinedCursor = MakeCode("34000") 218 UndefinedDatabase = MakeCode("3D000") 219 UndefinedFunction = MakeCode("42883") 220 UndefinedPreparedStatement = MakeCode("26000") 221 UndefinedSchema = MakeCode("3F000") 222 UndefinedTable = MakeCode("42P01") 223 UndefinedParameter = MakeCode("42P02") 224 UndefinedObject = MakeCode("42704") 225 DuplicateColumn = MakeCode("42701") 226 DuplicateCursor = MakeCode("42P03") 227 DuplicateDatabase = MakeCode("42P04") 228 DuplicateFunction = MakeCode("42723") 229 DuplicatePreparedStatement = MakeCode("42P05") 230 DuplicateSchema = MakeCode("42P06") 231 DuplicateRelation = MakeCode("42P07") 232 DuplicateAlias = MakeCode("42712") 233 DuplicateObject = MakeCode("42710") 234 AmbiguousColumn = MakeCode("42702") 235 AmbiguousFunction = MakeCode("42725") 236 AmbiguousParameter = MakeCode("42P08") 237 AmbiguousAlias = MakeCode("42P09") 238 InvalidColumnReference = MakeCode("42P10") 239 InvalidColumnDefinition = MakeCode("42611") 240 InvalidCursorDefinition = MakeCode("42P11") 241 InvalidDatabaseDefinition = MakeCode("42P12") 242 InvalidFunctionDefinition = MakeCode("42P13") 243 InvalidPreparedStatementDefinition = MakeCode("42P14") 244 InvalidSchemaDefinition = MakeCode("42P15") 245 InvalidTableDefinition = MakeCode("42P16") 246 InvalidObjectDefinition = MakeCode("42P17") 247 FileAlreadyExists = MakeCode("42C01") 248 // Section: Class 44 - WITH CHECK OPTION Violation 249 WithCheckOptionViolation = MakeCode("44000") 250 // Section: Class 53 - Insufficient Resources 251 InsufficientResources = MakeCode("53000") 252 DiskFull = MakeCode("53100") 253 OutOfMemory = MakeCode("53200") 254 TooManyConnections = MakeCode("53300") 255 ConfigurationLimitExceeded = MakeCode("53400") 256 // Section: Class 54 - Program Limit Exceeded 257 ProgramLimitExceeded = MakeCode("54000") 258 StatementTooComplex = MakeCode("54001") 259 TooManyColumns = MakeCode("54011") 260 TooManyArguments = MakeCode("54023") 261 // Section: Class 55 - Object Not In Prerequisite State 262 ObjectNotInPrerequisiteState = MakeCode("55000") 263 ObjectInUse = MakeCode("55006") 264 CantChangeRuntimeParam = MakeCode("55P02") 265 LockNotAvailable = MakeCode("55P03") 266 // Section: Class 57 - Operator Intervention 267 OperatorIntervention = MakeCode("57000") 268 QueryCanceled = MakeCode("57014") 269 AdminShutdown = MakeCode("57P01") 270 CrashShutdown = MakeCode("57P02") 271 CannotConnectNow = MakeCode("57P03") 272 DatabaseDropped = MakeCode("57P04") 273 // Section: Class 58 - System Error 274 System = MakeCode("58000") 275 Io = MakeCode("58030") 276 UndefinedFile = MakeCode("58P01") 277 DuplicateFile = MakeCode("58P02") 278 // Section: Class F0 - Configuration File Error 279 ConfigFile = MakeCode("F0000") 280 LockFileExists = MakeCode("F0001") 281 // Section: Class HV - Foreign Data Wrapper Error (SQL/MED) 282 FdwError = MakeCode("HV000") 283 FdwColumnNameNotFound = MakeCode("HV005") 284 FdwDynamicParameterValueNeeded = MakeCode("HV002") 285 FdwFunctionSequenceError = MakeCode("HV010") 286 FdwInconsistentDescriptorInformation = MakeCode("HV021") 287 FdwInvalidAttributeValue = MakeCode("HV024") 288 FdwInvalidColumnName = MakeCode("HV007") 289 FdwInvalidColumnNumber = MakeCode("HV008") 290 FdwInvalidDataType = MakeCode("HV004") 291 FdwInvalidDataTypeDescriptors = MakeCode("HV006") 292 FdwInvalidDescriptorFieldIdentifier = MakeCode("HV091") 293 FdwInvalidHandle = MakeCode("HV00B") 294 FdwInvalidOptionIndex = MakeCode("HV00C") 295 FdwInvalidOptionName = MakeCode("HV00D") 296 FdwInvalidStringLengthOrBufferLength = MakeCode("HV090") 297 FdwInvalidStringFormat = MakeCode("HV00A") 298 FdwInvalidUseOfNullPointer = MakeCode("HV009") 299 FdwTooManyHandles = MakeCode("HV014") 300 FdwOutOfMemory = MakeCode("HV001") 301 FdwNoSchemas = MakeCode("HV00P") 302 FdwOptionNameNotFound = MakeCode("HV00J") 303 FdwReplyHandle = MakeCode("HV00K") 304 FdwSchemaNotFound = MakeCode("HV00Q") 305 FdwTableNotFound = MakeCode("HV00R") 306 FdwUnableToCreateExecution = MakeCode("HV00L") 307 FdwUnableToCreateReply = MakeCode("HV00M") 308 FdwUnableToEstablishConnection = MakeCode("HV00N") 309 // Section: Class P0 - PL/pgSQL Error 310 PLpgSQL = MakeCode("P0000") 311 RaiseException = MakeCode("P0001") 312 NoDataFound = MakeCode("P0002") 313 TooManyRows = MakeCode("P0003") 314 AssertFailure = MakeCode("P0004") 315 // Section: Class XX - Internal Error 316 Internal = MakeCode("XX000") 317 DataCorrupted = MakeCode("XX001") 318 IndexCorrupted = MakeCode("XX002") 319 ) 320 321 // The following errors are CockroachDB-specific. 322 323 var ( 324 // Uncategorized is used for errors that flow out to a client 325 // when there's no code known yet. 326 Uncategorized = MakeCode("XXUUU") 327 328 // CCLRequired signals that a CCL binary is required to complete this 329 // task. 330 CCLRequired = MakeCode("XXC01") 331 332 // CCLValidLicenseRequired signals that a valid CCL license is 333 // required to complete this task. 334 CCLValidLicenseRequired = MakeCode("XXC02") 335 336 // TransactionCommittedWithSchemaChangeFailure signals that the 337 // non-DDL payload of a transaction was committed successfully but 338 // some DDL operation failed, without rolling back the rest of the 339 // transaction. 340 // 341 // We define a separate code instead of reusing a code from 342 // PostgreSQL (like StatementCompletionUnknown) because that makes 343 // it easier to document the error (this code only occurs in this 344 // particular situation) in a way that's unique to CockroachDB. 345 // 346 // We also use a "XX" code for this for several reasons: 347 // - it needs to override any other pg code set "underneath" in the cause. 348 // - it forces implementers of logic tests to be mindful about 349 // this situation. The logic test runner will remind the implementer 350 // that: 351 // serious error with code "XXA00" occurred; if expected, 352 // must use 'error pgcode XXA00 ...' 353 TransactionCommittedWithSchemaChangeFailure = MakeCode("XXA00") 354 355 // Class 22C - Semantic errors in the structure of a SQL statement. 356 357 // ScalarOperationCannotRunWithoutFullSessionContext signals that an 358 // operator or built-in function was used that requires a full session 359 // context and thus cannot be run in a background job or away from the SQL 360 // gateway. 361 ScalarOperationCannotRunWithoutFullSessionContext = MakeCode("22C01") 362 363 // Class 55C - Object Not In Prerequisite State (Cockroach extension) 364 365 // SchemaChangeOccurred signals that a DDL change to the targets of a 366 // CHANGEFEED has lead to its termination. If this error code is received 367 // the CHANGEFEED will have previously emitted a resolved timestamp which 368 // precedes the hlc timestamp of the relevant DDL transaction. 369 SchemaChangeOccurred = MakeCode("55C01") 370 371 // NoPrimaryKey signals that a table descriptor is invalid because the table 372 // does not have a primary key. 373 NoPrimaryKey = MakeCode("55C02") 374 375 // Class 58C - System errors related to CockroachDB node problems. 376 377 // RangeUnavailable signals that some data from the cluster cannot be 378 // accessed (e.g. because all replicas awol). 379 RangeUnavailable = MakeCode("58C00") 380 381 // InternalConnectionFailure refers to a networking error encountered 382 // internally on a connection between different Cockroach nodes. 383 InternalConnectionFailure = MakeCode("58C01") 384 385 // ProxyConnectionError is returned by the sqlproxyccl and it indicates a 386 // problem establishing the connection through the proxy. 387 ProxyConnectionError = MakeCode("08C00") 388 389 // Class XC - cockroach extension. 390 // CockroachDB distributed system related errors. 391 392 // UnsatisfiableBoundedStaleness signals that the bounded staleness query 393 // cannot be satisfied. 394 UnsatisfiableBoundedStaleness = MakeCode("XCUBS") 395 396 // QueryNotRunningInHomeRegion signals that a query is not running in its 397 // home region. 398 QueryNotRunningInHomeRegion = MakeCode("XCHR1") 399 400 // QueryHasNoHomeRegion signals that a query has no home region. 401 QueryHasNoHomeRegion = MakeCode("XCHR2") 402 403 // ExperimentalFeature signals that a feature we supported experimentally is being 404 // used without the session variable being enabled. 405 ExperimentalFeature = MakeCode("XCEXF") 406 ) 407 408 var pgCodeRegexp = regexp.MustCompile(`[A-Z0-9]{5}`) 409 410 // IsValidPGCode returns true if the given code is a valid error code. Note that 411 // this does not check if the code is one of the pre-defined error codes like 412 // "Syntax" or "InvalidName" - instead, it checks that the format of the code is 413 // valid. This is because it is possible for users to throw and catch arbitrary 414 // error codes in PLpgSQL routines. 415 func IsValidPGCode(code string) bool { 416 // The code must consist of 5 digits and/or upper-case ASCII letters. 417 return pgCodeRegexp.MatchString(code) 418 }