PG

PostgreSQL错误代码

已邀请:

附录 A. PostgreSQL错误代码

PostgreSQL服务器发出的所有消息都被赋予了五个字符错误代码,这遵循 SQL 标准对“SQLSTATE”代码的习惯。需要知道发生了什么错误条件的应用通常应该测试错误代码, 而不是查看文本形式的错误消息。这些错误代码轻易不会在PostgreSQL的版本之间改变,并且一般也不会随着错误消息的本地化而改变。请注意有些(但不是全部)PostgreSQL生成的错误代码是由 SQL 标准定义的;有些标准没有定义的额外错误代码是PostgreSQL发明的或者是从其它数据库借用的。

根据标准,错误代码的前两个字符表示错误类别,而后三个字符表示在该类别内的一种特定情况。因此, 那些不能识别特定错误代码的应用仍然可以从错误类别中推断要做什么。

表 A.1中列出了PostgreSQL 12.2定义的所有错误代码(有些实际上目前并没有使用,但是 SQL 标准中有定义)。错误类别也在其中列出。对于每个错误类别都有一个 “标准”错误代码,它的最后三个字符是000。这个代码只用于那些属于该类别但是没有被赋予更特定代码的错误情况。

“情况名称”列中显示的符号是在PL/pgSQL中使用的情况名称。情况名称可以被写成大写或小写形式(注意PL/pgSQL不识别警告(与错误不同)情况名称,它们是类别 00、01 和 02)。

对于某些类型的错误,服务器会报告与错误相关的数据库对象(一个表、表列、数据类型或约束)的名称。例如,导致一个unique_violation错误的唯一约束的名称。这些名字被包含在错误报告消息的独立域中,这样应用就不必从可能是本地化的人类可读的消息文本中抽取它们。到PostgreSQL 9.3 位置,对于这个特性的完全覆盖只在 SQLSTATE 类别 23 (完整性约束未被)的错误中存在,但是很可能会在未来进行扩展。

表 A.1. PostgreSQL错误代码

错误代码情况名称
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
22013invalid_preceding_or_following_size
2201Binvalid_regular_expression
2201Winvalid_row_count_in_limit_clause
2201Xinvalid_row_count_in_result_offset_clause
2202Hinvalid_tablesample_argument
2202Ginvalid_tablesample_repeat
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
2200Hsequence_generator_limit_exceeded
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
22030duplicate_json_object_key_value
22032invalid_json_text
22033invalid_sql_json_subscript
22034more_than_one_sql_json_item
22035no_sql_json_item
22036non_numeric_sql_json_item
22037non_unique_keys_in_a_json_object
22038singleton_sql_json_item_required
22039sql_json_array_not_found
2203Asql_json_member_not_found
2203Bsql_json_number_not_found
2203Csql_json_object_not_found
2203Dtoo_many_json_array_elements

要回复问题请先登录注册