PostgreSQL Error Code Lookup
Paste a SQLSTATE code, a condition name or the whole error line your driver printed, and this Postgres error code lookup answers with the condition behind it, the class it sits in and what usually produces it. Matching happens in the browser, against a table generated from the PostgreSQL 18 source.
Takes 23505, unique_violation, or a line lifted out of a log with the code somewhere in it.
Class 23, Integrity Constraint Violation
What it means
A row you tried to write carries a value a unique index already holds.
How it arrives
ERROR: duplicate key value violates unique constraint "users_email_key"
DETAIL: Key (email)=(ada@example.com) already exists.While loading data
Loading the same table twice without emptying it first returns this code for every row with a unique column, which is why it is the failure people meet most often.
What causes it
- The same row is written twice, usually because a script reran after a partial failure.
- The sequence behind an id column sits below the ids already in the table, so the next generated value collides with one of them.
- Two sources disagree about what makes a row distinct, and trimming or case folding turns what looked like two rows into one key.
What to check
The DETAIL line names both the column and the value. Query the table for that value before changing anything, because the answer decides whether the incoming row is a duplicate or the constraint is stricter than the data can be.
Class 23 holds 7 codes. Read the whole class in the list below.
23505, unique_violation. Read straight off the five character code in what you pasted. Whatever you paste stays in this tab.
Enter jumps to the code in the list below. Escape clears the field.
The full PostgreSQL error codes list
Every SQLSTATE value PostgreSQL 18 can report, class by class, in the order the server source lists them. A teal dot marks the thirty that have a written card, ten of the rest are warnings rather than errors, and one reports success.
Showing all 262 codes.
Class 00Successful Completion
- 00000successful_completion
Class 01Warning
- 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 02No Data (this is also a warning class per the SQL standard)
- 02000no_data
- 02001no_additional_dynamic_result_sets_returned
Class 03SQL Statement Not Yet Complete
- 03000sql_statement_not_yet_complete
Class 08Connection Exception
- 08000connection_exception
- 08003connection_does_not_exist
- Has a card. 08006connection_failure
- Has a card. 08001sqlclient_unable_to_establish_sqlconnection
- 08004sqlserver_rejected_establishment_of_sqlconnection
- 08007transaction_resolution_unknown
- 08P01protocol_violation
Class 09Triggered Action Exception
- 09000triggered_action_exception
Class 0AFeature Not Supported
- Has a card. 0A000feature_not_supported
Class 0BInvalid Transaction Initiation
- 0B000invalid_transaction_initiation
Class 0FLocator Exception
- 0F000locator_exception
- 0F001invalid_locator_specification
Class 0LInvalid Grantor
- 0L000invalid_grantor
- 0LP01invalid_grant_operation
Class 0PInvalid Role Specification
- 0P000invalid_role_specification
Class 0ZDiagnostics Exception
- 0Z000diagnostics_exception
- 0Z002stacked_diagnostics_accessed_without_active_handler
Class 10XQuery Error
- 10608invalid_argument_for_xquery
Class 20Case Not Found
- 20000case_not_found
Class 21Cardinality Violation
- 21000cardinality_violation
Class 22Data Exception
- 22000data_exception
- 2202Earray_subscript_error
- 22021character_not_in_repertoire
- Has a card. 22008datetime_field_overflow
- Has a card. 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
- Has a card. 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
- Has a card. 22003numeric_value_out_of_range
- 2200Hsequence_generator_limit_exceeded
- 22026string_data_length_mismatch
- Has a card. 22001string_data_right_truncation
- 22011substring_error
- 22027trim_error
- 22024unterminated_c_string
- 2200Fzero_length_character_string
- 22P01floating_point_exception
- Has a card. 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
- 22031invalid_argument_for_sql_json_datetime_function
- 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
- 2203Etoo_many_json_object_members
- 2203Fsql_json_scalar_required
- 2203Gsql_json_item_cannot_be_cast_to_target_type
Class 23Integrity Constraint Violation
- 23000integrity_constraint_violation
- 23001restrict_violation
- Has a card. 23502not_null_violation
- Has a card. 23503foreign_key_violation
- Has a card. 23505unique_violation
- Has a card. 23514check_violation
- Has a card. 23P01exclusion_violation
Class 24Invalid Cursor State
- 24000invalid_cursor_state
Class 25Invalid Transaction State
- 25000invalid_transaction_state
- 25001active_sql_transaction
- 25002branch_transaction_already_active
- 25008held_cursor_requires_same_isolation_level
- 25003inappropriate_access_mode_for_branch_transaction
- 25004inappropriate_isolation_level_for_branch_transaction
- 25005no_active_sql_transaction_for_branch_transaction
- 25006read_only_sql_transaction
- 25007schema_and_data_statement_mixing_not_supported
- 25P01no_active_sql_transaction
- Has a card. 25P02in_failed_sql_transaction
- 25P03idle_in_transaction_session_timeout
- 25P04transaction_timeout
Class 26Invalid SQL Statement Name
- 26000invalid_sql_statement_name
Class 27Triggered Data Change Violation
- 27000triggered_data_change_violation
Class 28Invalid Authorization Specification
- Has a card. 28000invalid_authorization_specification
- Has a card. 28P01invalid_password
Class 2BDependent Privilege Descriptors Still Exist
- 2B000dependent_privilege_descriptors_still_exist
- 2BP01dependent_objects_still_exist
Class 2DInvalid Transaction Termination
- 2D000invalid_transaction_termination
Class 2FSQL Routine Exception
- 2F000sql_routine_exception
- 2F005function_executed_no_return_statement
- 2F002modifying_sql_data_not_permitted
- 2F003prohibited_sql_statement_attempted
- 2F004reading_sql_data_not_permitted
Class 34Invalid Cursor Name
- 34000invalid_cursor_name
Class 38External Routine Exception
- 38000external_routine_exception
- 38001containing_sql_not_permitted
- 38002modifying_sql_data_not_permitted
- 38003prohibited_sql_statement_attempted
- 38004reading_sql_data_not_permitted
Class 39External Routine Invocation Exception
- 39000external_routine_invocation_exception
- 39001invalid_sqlstate_returned
- 39004null_value_not_allowed
- 39P01trigger_protocol_violated
- 39P02srf_protocol_violated
- 39P03event_trigger_protocol_violated
Class 3BSavepoint Exception
- 3B000savepoint_exception
- 3B001invalid_savepoint_specification
Class 3DInvalid Catalog Name
- Has a card. 3D000invalid_catalog_name
Class 3FInvalid Schema Name
- 3F000invalid_schema_name
Class 40Transaction Rollback
- 40000transaction_rollback
- 40002transaction_integrity_constraint_violation
- Has a card. 40001serialization_failure
- 40003statement_completion_unknown
- Has a card. 40P01deadlock_detected
Class 42Syntax Error or Access Rule Violation
- 42000syntax_error_or_access_rule_violation
- Has a card. 42601syntax_error
- Has a card. 42501insufficient_privilege
- 42846cannot_coerce
- 42803grouping_error
- 42P20windowing_error
- 42P19invalid_recursion
- 42830invalid_foreign_key
- 42602invalid_name
- 42622name_too_long
- 42939reserved_name
- Has a card. 42804datatype_mismatch
- 42P18indeterminate_datatype
- 42P21collation_mismatch
- 42P22indeterminate_collation
- 42809wrong_object_type
- 428C9generated_always
- Has a card. 42703undefined_column
- Has a card. 42883undefined_function
- Has a card. 42P01undefined_table
- 42P02undefined_parameter
- 42704undefined_object
- 42701duplicate_column
- 42P03duplicate_cursor
- 42P04duplicate_database
- 42723duplicate_function
- 42P05duplicate_prepared_statement
- 42P06duplicate_schema
- Has a card. 42P07duplicate_table
- 42712duplicate_alias
- 42710duplicate_object
- 42702ambiguous_column
- 42725ambiguous_function
- 42P08ambiguous_parameter
- 42P09ambiguous_alias
- 42P10invalid_column_reference
- 42611invalid_column_definition
- 42P11invalid_cursor_definition
- 42P12invalid_database_definition
- 42P13invalid_function_definition
- 42P14invalid_prepared_statement_definition
- 42P15invalid_schema_definition
- 42P16invalid_table_definition
- 42P17invalid_object_definition
Class 44WITH CHECK OPTION Violation
- 44000with_check_option_violation
Class 53Insufficient Resources
- 53000insufficient_resources
- 53100disk_full
- 53200out_of_memory
- Has a card. 53300too_many_connections
- 53400configuration_limit_exceeded
Class 54Program Limit Exceeded
- 54000program_limit_exceeded
- 54001statement_too_complex
- 54011too_many_columns
- 54023too_many_arguments
Class 55Object Not In Prerequisite State
- 55000object_not_in_prerequisite_state
- 55006object_in_use
- 55P02cant_change_runtime_param
- Has a card. 55P03lock_not_available
- 55P04unsafe_new_enum_value_usage
Class 57Operator Intervention
- 57000operator_intervention
- Has a card. 57014query_canceled
- 57P01admin_shutdown
- 57P02crash_shutdown
- 57P03cannot_connect_now
- 57P04database_dropped
- 57P05idle_session_timeout
Class 58System Error (errors external to PostgreSQL itself)
- 58000system_error
- 58030io_error
- 58P01undefined_file
- 58P02duplicate_file
- 58P03file_name_too_long
Class F0Configuration File Error
- F0000config_file_error
- F0001lock_file_exists
Class HVForeign Data Wrapper Error (SQL/MED)
- HV000fdw_error
- HV005fdw_column_name_not_found
- HV002fdw_dynamic_parameter_value_needed
- HV010fdw_function_sequence_error
- HV021fdw_inconsistent_descriptor_information
- HV024fdw_invalid_attribute_value
- HV007fdw_invalid_column_name
- HV008fdw_invalid_column_number
- HV004fdw_invalid_data_type
- HV006fdw_invalid_data_type_descriptors
- HV091fdw_invalid_descriptor_field_identifier
- HV00Bfdw_invalid_handle
- HV00Cfdw_invalid_option_index
- HV00Dfdw_invalid_option_name
- HV090fdw_invalid_string_length_or_buffer_length
- HV00Afdw_invalid_string_format
- HV009fdw_invalid_use_of_null_pointer
- HV014fdw_too_many_handles
- HV001fdw_out_of_memory
- HV00Pfdw_no_schemas
- HV00Jfdw_option_name_not_found
- HV00Kfdw_reply_handle
- HV00Qfdw_schema_not_found
- HV00Rfdw_table_not_found
- HV00Lfdw_unable_to_create_execution
- HV00Mfdw_unable_to_create_reply
- HV00Nfdw_unable_to_establish_connection
Class P0PL/pgSQL Error
- P0000plpgsql_error
- P0001raise_exception
- P0002no_data_found
- P0003too_many_rows
- P0004assert_failure
Class XXInternal Error
- XX000internal_error
- XX001data_corrupted
- XX002index_corrupted
What it does and how to use it
The field takes whatever you have in front of you. A bare 23505 resolves on its own, and so does the condition name unique_violation. Paste a line out of a log and the code is pulled out of the noise around it; paste one with no code in it at all and the wording is matched instead, which is how duplicate key value violates unique constraint lands on 23505 without a number being typed.
Every driver carries the code under a name of its own. On node-postgres it arrives as err.code; psycopg 2 spells it pgcode and psycopg 3 renamed the attribute to sqlstate. Java reads it back from getSQLState() on the SQLException that was thrown. When you are sitting in psql and the code is not on screen, \errverbose reprints the last error at full verbosity with the SQLSTATE in it.
Under the panel is the whole table, class by class, and every row carries an anchor, so a link ending #23503 opens the page on the foreign key violation.
The Postgres error codes you meet while loading data
Four integrity constraints account for most of what stops a data load. 23505 is the unique violation a rerun of a script comes back with, and it also turns up once manual inserts have left an identity sequence behind the table, which the insert that fails right after a successful load goes through. 23503 is the foreign key violation, and its DETAIL line separates a key missing from the parent table from a parent row a child still points at, which is referential integrity doing its job. 23502 prints the whole failing row, so the null is visible in position, and 23514 names the check constraint that turned the row down.
The other two arrive from somewhere other than your own rows. A deadlock, 40P01, means two transactions were each waiting on what the other held, and PostgreSQL rolled one of them back to break the cycle. 55P03 is a lock that was not free when a statement asked for it without waiting, which a loader meets when it empties a table something else is still reading.
Frequently asked questions
The class is the first two characters, the code is all five. Class 23 is integrity constraint violations and 23505 is the one about a unique index, so reading the class first already narrows the problem down.
It depends on the driver. node-postgres puts it on err.code, psycopg 2 on pgcode, psycopg 3 on sqlstate, and JDBC returns it from getSQLState(). In psql it stays hidden until \errverbose reprints the last error with the code in it.
A few of them map cleanly enough to be worth doing, 23505 as a 409 and 23503 or 23514 as a 422 being the common choices in APIs. Most of the rest do not map at all, and a blanket rule turns a bug in your own SQL into a 400 that blames the caller.
No. The code table ships with the page and the matching runs in this tab, so a pasted log line is never uploaded. What gets recorded is that a lookup ran and which of the 262 codes it landed on.
PostgreSQL 18, generated from errcodes.txt in the server source, the file Appendix A of the manual is built from. Codes get added between versions and almost never change meaning.
Cards are written for the thirty codes people search for, and a teal dot in the list marks them. The other 232 carry a condition name and a class, which is PostgreSQL's own wording and usually enough to confirm the row.
It is free and there is nothing to sign up for. The page is one of a set of free PostgreSQL tools that all run in the browser.
They are what a dataset assembled by hand tends to break: a duplicate key, a child without a parent, a missing NOT NULL column, a check constraint nobody had read. Seedfast reads the live schema on every run and generates rows that fit the constraints it finds there.
Other free PostgreSQL tools
- Syntax checkerRuns your statement through the grammar Postgres itself uses and reports the same message the server would, with the character position it stopped at.
- Truncate generatorPaste the DDL of a schema and it writes the TRUNCATE statement for every table in it, with RESTART IDENTITY and CASCADE where you want them. When cascading is not an option, it gives you the DELETE order instead.
- PlaygroundA real Postgres server compiled to WebAssembly, running inside the tab. Create tables, insert rows, join them, and read the plan, with no server behind it.
Further reading: The Postgres Insert That Fails Right After a Successful Load.