PostgreSQL 和openGauss错误代码整理(一)

本文涉及的产品
云原生数据库 PolarDB MySQL 版,通用型 2核4GB 50GB
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
简介: PostgreSQL 和openGauss错误代码整理

一、 PostgreSQL 错误信息的设计

  • All messages emitted by the PostgreSQL server are assigned five-character error codes that follow the SQL standard’s conventions for “SQLSTATE” codes. Applications that need to know which error condition has occurred should usually test the error code, rather than looking at the textual error message. The error codes are less likely to change across PostgreSQL releases, and also are not subject to change due to localization of error messages. Note that some, but not all, of the error codes produced by PostgreSQL are defined by the SQL standard; some additional error codes for conditions not defined by the standard have been invented or borrowed from other databases.

PostgreSQL 服务器发出的所有消息都分配有五个字符的错误代码,遵循 SQL 标准的“SQLSTATE”代码约定。需要知道发生了哪种错误情况的应用程序通常应该测试错误代码,而不是查看文本错误消息。错误代码不太可能在 PostgreSQL 版本之间更改,并且也不会由于错误消息的本地化而发生更改。请注意,PostgreSQL 产生的一些但不是全部的错误代码是由 SQL 标准定义的;标准未定义的一些附加错误代码已被发明或从其他数据库借用。

  • According to the standard, the first two characters of an error code denote a class of errors, while the last three characters indicate a specific condition within that class. Thus, an application that does not recognize the specific error code might still be able to infer what to do from the error class.

根据标准,错误代码的前两个字符表示一类错误,而后三个字符表示该类中的特定条件。因此,无法识别特定错误代码的应用程序可能仍然能够从错误类中推断出要做什么

Table A. lists all the error codes defined in PostgreSQL 15.0. (Some are not actually used at present, but are defined by the SQL standard.) The error classes are also shown. For each error class there is a “standard” error code having the last three characters 000. This code is used only for error conditions that fall within the class but do not have any more-specific code assigned.

表 A.1 列出了 PostgreSQL 15.0 中定义的所有错误代码。 (有些目前没有实际使用,但由SQL标准定义。)还显示了错误类。对于每个错误类别,都有一个最后三个字符为 000 的“标准”错误代码。此代码仅用于属于该类别但没有分配任何更具体代码的错误条件。

  • The symbol shown in the column “Condition Name” is the condition name to use in PL/pgSQL. Condition names can be written in either upper or lower case. (Note that PL/pgSQL does not recognize warning, as opposed to error, condition names; those are classes 00, 01, and 02.)

“条件名称”列中显示的符号是在 PL/pgSQL 中使用的条件名称。条件名称可以大写或小写。 (请注意,PL/pgSQL 不识别警告,而不是错误,条件名称;它们是类 00、01 和 02。)

  • For some types of errors, the server reports the name of a database object (a table, table column, data type, or constraint) associated with the error; for example, the name of the unique constraint that caused a unique_violation error. Such names are supplied in separate fields of the error report message so that applications need not try to extract them from the possibly-localized human-readable text of the message. As of PostgreSQL 9.3, complete coverage for this feature exists only for errors in SQLSTATE class 23 (integrity constraint violation), but this is likely to be expanded in future.

对于某些类型的错误,服务器会报告与错误相关的数据库对象(表、表列、数据类型或约束)的名称;例如,导致 unique_violation 错误的唯一约束的名称。此类名称在错误报告消息的单独字段中提供,因此应用程序无需尝试从消息的可能本地化的人类可读文本中提取它们。从 PostgreSQL 9.3 开始,此功能的完全覆盖仅存在于 SQLSTATE 类 23 中的错误(违反完整性约束),但将来可能会扩展。

二、 openGauss错误信息设计

  • 根据X/Open和SQL Access Group SQL CAE规范(1992)所进行的定义,SQLERROR返回SQLSTATE值。SQLSTATE值是包含五个字符的字符串,由2个字符的SQL错误类和3个字符的子类构成。五个字符包含数值或者大写字母, 代表各种错误或者警告条件的代码。成功的状态是由00000标识的。SQLSTATE代码大多数情况下都是定义在SQL标准里的。
  • openGauss也遵循SQL标准返回错误码的SQLSTATE值,详细说明请参见

三、 PostgreSQL and openGauss error code


错误码SQLSTATE值 condition name 错误码含义 共有 PG 独有 OG 独有
Class 00 — Successful Completion/类 00 - 成功完成
00000 successful_completion 成功完成
Class 01 — Warning/类 01 - 警告
1000 warning 警告
0100C dynamic_result_sets_returned 返回了动态结果集
1008 implicit_zero_bit_padding 警告,隐含补齐了零比特位
1003 null_value_eliminated_in_set_function 在集合函数里消除了NULL
1007 privilege_not_granted 没有赋予权限
1006 privilege_not_revoked 没有撤销权限
1004 string_data_right_truncation 字符串数据在右端截断
01P01 deprecated_feature 废弃的特性
Class 02 — No Data (this is also a warning class per the SQL standard)/类 02 - 没有数据(按照SQL标准的要求,这也是警告类)
2000 no_data 没有数据
2001 no_additional_dynamic_result_sets_returned 返回了无附加动态结果集
Class 03 — SQL Statement Not Yet Complete/类 03 - SQL语句尚未结束
3000 sql_statement_not_yet_complete SQL语句尚未结束
Class 08 — Connection Exception/类 08 - 连接异常
8000 connection_exception 连接异常
8003 connection_does_not_exist 连接不存在
8006 connection_failure 连接失败
8001 sqlclient_unable_to_establish_sqlconnection SQL客户端不能建立SQL连接
8004 sqlserver_rejected_establishment_of_sqlconnection SQL服务器拒绝建立SQL连接
8007 transaction_resolution_unknown 未知的事务解析
08P01 protocol_violation 违反协议
Class 09 — Triggered Action Exception/类09 - 触发动作异常
9000 triggered_action_exception 触发动作异常
Class 0A — Feature Not Supported/类 0A - 不支持特性
0A000 feature_not_supported 不支持此特性
0A100 stream_not_supported 不支持流
Class 0B — Invalid Transaction Initiation/类 0B - 非法事务初始化
0B000 非法事务初始化
Class 0F — Locator Exception/类 0F - 定位器异常
0F000 locator_exception 定位器异常
0F001 invalid_locator_specification 非法的定位器声明
Class 0L — Invalid Grantor/类 0L - 非法赋权者
0L000 invalid_grantor 非法赋权者
0LP01 invalid_grant_operation `
Class 0P — Invalid Role Specification/类 0P - 非法角色声明
0P000 非法角色声明
Class 0Z — Diagnostics Exception/类 0Z - 诊断异常
0Z000 诊断异常
0Z002 stacked_diagnostics_accessed_without_active_handler 没有在活跃的处理程序下访问堆栈诊断信息
Class 20 — Case Not Found/类 20 - 未找到CASE
20000 case_not_found 未找到CASE
Class 21 — Cardinality Violation/类 21 - 势违例
21000 cardinality_violation 势违例
Class 22 — Data Exception/类 22 - 数据异常
22000 data_exception 数据异常
2202E array_subscript_error 数组下标错误
22021 character_not_in_repertoire 字符不被计算机命令系统识别
22008 datetime_field_overflow 日期时间字段溢出
22012 division_by_zero 被零除
22005 error_in_assignment 赋值中出错
2200B escape_character_conflict 转义字符冲突
22022 indicator_overflow 指示器溢出
22015 interval_field_overflow 内部字段溢出
2201E invalid_argument_for_logarithm 对数运算的非法参数
22014 invalid_argument_for_ntile_function NTILE函数的非法参数
22016 invalid_argument_for_nth_value_function N值函数的非法参数
2201F invalid_argument_for_power_function 幂函数的非法参数
2201G invalid_argument_for_width_bucket_function 宽桶函数的非法参数
22018 invalid_character_value_for_cast 类型转换时非法的字符值
22007 invalid_datetime_format 非法日期时间格式
22019 invalid_escape_character 非法的转义字符
2200D invalid_escape_octet 非法的转义字节
22025 invalid_escape_sequence 非法转义序列
22P06 nonstandard_use_of_escape_character 非标准使用转义字符
22010 invalid_indicator_parameter_value 非法指示器参数值
22023 invalid_parameter_value 非法参数值
22013 invalid_preceding_or_following_size
2201B invalid_regular_expression 非法正则表达式
2201W invalid_row_count_in_limit_clause LIMIT子句中行号非法
2201X invalid_row_count_in_result_offset_clause 结果集中行号非法
2202H invalid_tablesample_argument 非法抽样参数
2202G invalid_tablesample_repeat 非法重复抽样
22009 invalid_time_zone_displacement_value 非法时区显示值
2200C invalid_use_of_escape_character 非法使用转义字符
2200G most_specific_type_mismatch 最相关类型不匹配
22004 null_value_not_allowed 不允许NULL值
22002 null_value_no_indicator_parameter NULL值不能做指示器参数
22003 numeric_value_out_of_range 数值越界
22017 dop_value_out_of_range 并发数超限
2200H sequence_generator_limit_exceeded
22026 string_data_length_mismatch 字符串数据长度不匹配
22028 regexp_mismatch 正则表达式不匹配
22001 string_data_right_truncation 字符串数据右截断
22011 substring_error 抽取子字符串错误
22027 trim_error 截断错误
22024 unterminated_c_string 未结束的C字符串
2200F zero_length_character_string 零长度的字符串
22P01 floating_point_exception 浮点异常
22P02 invalid_text_representation 非法文本表现形式
22P03 invalid_binary_representation 非法二进制表现形式
22P04 bad_copy_file_format 错误的COPY格式
22P05 untranslatable_character 不可翻译字符
22P06 cache_lookup_failed 内存查找失败
22P07 file_read_failed 文件读取失败
22P08 fetch_data_failed 获取数据失败
2200L not_an_xml_document 非XML文件
2200M invalid_xml_document 非法的XML文件
2200N invalid_xml_content 非法的XML内容
2200O invalid_xml_error_context 非法的XML错误信息
2200S invalid_xml_comment 非法的XML注释
2200T invalid_xml_processing_instruction 非法的XML处理命令
2200X relation_close_error 关闭RELATION错误
22030 duplicate_json_object_key_value
22031 invalid_argument_for_sql_json_datetime_function
22032 invalid_json_text
22033 invalid_sql_json_subscript
22034 more_than_one_sql_json_item
22035 no_sql_json_item
22036 non_numeric_sql_json_item
22037 non_unique_keys_in_a_json_object
22038 singleton_sql_json_item_required
22039 sql_json_array_not_found
2203A sql_json_member_not_found
2203B sql_json_number_not_found
2203C sql_json_object_not_found
2203D too_many_json_array_elements
2203E too_many_json_object_members
2203F sql_json_scalar_required
2203G sql_json_item_cannot_be_cast_to_target_type
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
存储 SQL 缓存
带你全面了解MySQL性能调优、错误代码总结和全局参数配置
本文主要介绍当前MySQL性能优化+原理+实战,包括以下方面: MySQL遇到的的错误及解决方法 全局参数文件配置详解。
741 0
|
关系型数据库 MySQL 数据库
一文剖析MySQL主从复制异常错误代码13114
一文剖析MySQL主从复制异常错误代码13114
788 0
|
12天前
|
关系型数据库 数据库 网络虚拟化
Docker环境下重启PostgreSQL数据库服务的全面指南与代码示例
由于时间和空间限制,我将在后续的回答中分别涉及到“Python中采用lasso、SCAD、LARS技术分析棒球运动员薪资的案例集锦”以及“Docker环境下重启PostgreSQL数据库服务的全面指南与代码示例”。如果你有任何一个问题的优先顺序或需要立即回答的,请告知。
22 0
|
11月前
|
SQL 关系型数据库 MySQL
MySQL数据库常见报错案例与错误代码说明
MySQL数据库常见报错案例与错误代码说明
280 0
|
10月前
|
关系型数据库 MySQL
mysql 错误代码:1293
mysql 错误代码:1293
|
关系型数据库 MySQL 数据安全/隐私保护
MySQL安装1045错误代码解决方案
MySQL安装1045错误代码解决方案
222 0
|
存储 SQL 安全
MYSQL的错误代码与释义大全
MYSQL的错误代码与释义大全
|
SQL 关系型数据库 MySQL
错误代码:1406列的数据太长-MySQL
错误代码:1406列的数据太长-MySQL
218 0
|
关系型数据库 MySQL 数据库
MySQL:错误代码:1118行大小太大(> 8126)将某些列更改为TEXT或BLOB
MySQL:错误代码:1118行大小太大(> 8126)将某些列更改为TEXT或BLOB
453 0
|
SQL 关系型数据库 MySQL
错误代码:2013查询期间丢失与MySQL服务器的连接
错误代码:2013查询期间丢失与MySQL服务器的连接
124 0