PostgreSQL error codes
Every SQLSTATE code PostgreSQL can raise, grouped by class as in the official appendix. The ones people actually run into have a full page: what the error means, why it happens and how to fix it.
Reading a PostgreSQL error
PostgreSQL identifies every error by a five-character SQLSTATE code. The first two characters are the class: 23 is integrity constraint violation, 42 is syntax error or access rule violation, 40 is transaction rollback, and so on. Codes ending in 000 are the generic code for their class.
psql shows the message, not the code. Run \set VERBOSITY verbose to see the SQLSTATE, or read it from your driver: SQLSTATE in JDBC and ODBC, e.pgcode in psycopg2, e.sqlstate in psycopg 3, err.code in node-postgres.
In PL/pgSQL you can trap an error by condition name (EXCEPTION WHEN unique_violation THEN) or by code (WHEN SQLSTATE '23505' THEN).
All PostgreSQL errors in this reference
262 codes, 63 with a full write-up (linked). Codes and messages are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes.
Successful Completion
| Code | Meaning |
|---|---|
00000
|
successful_completion
|
Warning
| Code | Meaning |
|---|---|
01000
|
warning
|
0100C
|
dynamic_result_sets_returned
|
01008
|
implicit_zero_bit_padding
|
01003
|
null_value_eliminated_in_set_function
|
01007
|
privilege_not_granted
|
01006
|
privilege_not_revoked
|
01004
|
string_data_right_truncation
|
01P01
|
deprecated_feature
|
No Data (this is also a warning class per the SQL standard)
| Code | Meaning |
|---|---|
02000
|
no_data
|
02001
|
no_additional_dynamic_result_sets_returned
|
SQL Statement Not Yet Complete
| Code | Meaning |
|---|---|
03000
|
sql_statement_not_yet_complete
|
Connection Exception
| Code | Meaning |
|---|---|
08000
|
connection_exception
|
08003
|
connection_does_not_exist
|
08006
|
connection failure
connection_failure
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
|
08001
|
unable to establish connection
sqlclient_unable_to_establish_sqlconnection
connection to server at "db.example.com" (10.0.0.5), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
|
08004
|
sqlserver_rejected_establishment_of_sqlconnection
|
08007
|
transaction_resolution_unknown
|
08P01
|
protocol_violation
|
Triggered Action Exception
| Code | Meaning |
|---|---|
09000
|
triggered_action_exception
|
Feature Not Supported
| Code | Meaning |
|---|---|
0A000
|
feature not supported
feature_not_supported
cross-database references are not implemented: "otherdb.public.orders"
|
Invalid Transaction Initiation
| Code | Meaning |
|---|---|
0B000
|
invalid_transaction_initiation
|
Locator Exception
| Code | Meaning |
|---|---|
0F000
|
locator_exception
|
0F001
|
invalid_locator_specification
|
Invalid Grantor
| Code | Meaning |
|---|---|
0L000
|
invalid_grantor
|
0LP01
|
invalid grant operation
invalid_grant_operation
grant options can only be granted to roles
|
Invalid Role Specification
| Code | Meaning |
|---|---|
0P000
|
invalid_role_specification
|
Diagnostics Exception
| Code | Meaning |
|---|---|
0Z000
|
diagnostics_exception
|
0Z002
|
stacked_diagnostics_accessed_without_active_handler
|
XQuery Error
| Code | Meaning |
|---|---|
10608
|
invalid_argument_for_xquery
|
Case Not Found
| Code | Meaning |
|---|---|
20000
|
case_not_found
|
Cardinality Violation
| Code | Meaning |
|---|---|
21000
|
more than one row returned by a subquery
cardinality_violation
more than one row returned by a subquery used as an expression
|
Data Exception
| Code | Meaning |
|---|---|
22000
|
data_exception
|
2202E
|
array_subscript_error
|
22021
|
invalid byte sequence for encoding
character_not_in_repertoire
invalid byte sequence for encoding "UTF8": 0xff
|
22008
|
date/time field value out of range
datetime_field_overflow
date/time field value out of range: "2026-13-01"
|
22012
|
division by zero
division_by_zero
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
|
22016
|
invalid_argument_for_nth_value_function
|
2201F
|
invalid_argument_for_power_function
|
2201G
|
invalid_argument_for_width_bucket_function
|
22018
|
invalid_character_value_for_cast
|
22007
|
invalid datetime format
invalid_datetime_format
invalid input syntax for type timestamp: "31/12/2026 25:00"
|
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
invalid_parameter_value
invalid value for parameter "TimeZone": "Mars/Olympus"
|
22013
|
invalid_preceding_or_following_size
|
2201B
|
invalid_regular_expression
|
2201W
|
invalid_row_count_in_limit_clause
|
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
|
22002
|
null_value_no_indicator_parameter
|
22003
|
numeric value out of range
numeric_value_out_of_range
integer out of range
|
2200H
|
sequence_generator_limit_exceeded
|
22026
|
string_data_length_mismatch
|
22001
|
value too long for type
string_data_right_truncation
value too long for type character varying(20)
|
22011
|
substring_error
|
22027
|
trim_error
|
22024
|
unterminated_c_string
|
2200F
|
zero_length_character_string
|
22P01
|
floating_point_exception
|
22P02
|
invalid input syntax for type
invalid_text_representation
invalid input syntax for type integer: "abc"
|
22P03
|
invalid_binary_representation
|
22P04
|
bad_copy_file_format
|
22P05
|
untranslatable_character
|
2200L
|
not_an_xml_document
|
2200M
|
invalid_xml_document
|
2200N
|
invalid_xml_content
|
2200S
|
invalid_xml_comment
|
2200T
|
invalid_xml_processing_instruction
|
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
|
Integrity Constraint Violation
| Code | Meaning |
|---|---|
23000
|
integrity_constraint_violation
|
23001
|
restrict_violation
|
23502
|
null value violates not-null constraint
not_null_violation
null value in column "email" of relation "users" violates not-null constraint
DETAIL: Failing row contains (7, Ada, null).
|
23503
|
foreign key constraint violation
foreign_key_violation
insert or update on table "orders" violates foreign key constraint "orders_customer_id_fkey"
DETAIL: Key (customer_id)=(42) is not present in table "customers".
|
23505
|
duplicate key violates unique constraint
unique_violation
duplicate key value violates unique constraint "users_email_key"
DETAIL: Key (email)=([email protected]) already exists.
|
23514
|
check constraint violation
check_violation
new row for relation "orders" violates check constraint "orders_qty_check"
DETAIL: Failing row contains (12, -1).
|
23P01
|
exclusion constraint violation
exclusion_violation
conflicting key value violates exclusion constraint "bookings_room_during_excl"
DETAIL: Key (room_id, during)=(4, ["2026-05-01 10:00:00","2026-05-01 11:00:00")) conflicts with existing key (room_id, during)=(4, ["2026-05-01 10:30:00","2026-05-01 12:00:00")).
|
Invalid Cursor State
| Code | Meaning |
|---|---|
24000
|
invalid_cursor_state
|
Invalid Transaction State
| Code | Meaning |
|---|---|
25000
|
invalid_transaction_state
|
25001
|
cannot run inside a transaction block
active_sql_transaction
CREATE INDEX CONCURRENTLY cannot run inside a transaction block
|
25002
|
branch_transaction_already_active
|
25008
|
held_cursor_requires_same_isolation_level
|
25003
|
inappropriate_access_mode_for_branch_transaction
|
25004
|
inappropriate_isolation_level_for_branch_transaction
|
25005
|
no_active_sql_transaction_for_branch_transaction
|
25006
|
read-only SQL transaction
read_only_sql_transaction
cannot execute INSERT in a read-only transaction
|
25007
|
schema_and_data_statement_mixing_not_supported
|
25P01
|
no_active_sql_transaction
|
25P02
|
current transaction is aborted
in_failed_sql_transaction
current transaction is aborted, commands ignored until end of transaction block
|
25P03
|
idle-in-transaction session timeout
idle_in_transaction_session_timeout
terminating connection due to idle-in-transaction timeout
|
25P04
|
transaction_timeout
|
Invalid SQL Statement Name
| Code | Meaning |
|---|---|
26000
|
invalid_sql_statement_name
|
Triggered Data Change Violation
| Code | Meaning |
|---|---|
27000
|
triggered_data_change_violation
|
Invalid Authorization Specification
| Code | Meaning |
|---|---|
28000
|
invalid authorization specification
invalid_authorization_specification
no pg_hba.conf entry for host "10.0.0.5", user "app", database "shop", no encryption
|
28P01
|
password authentication failed
invalid_password
password authentication failed for user "app"
|
Dependent Privilege Descriptors Still Exist
| Code | Meaning |
|---|---|
2B000
|
dependent_privilege_descriptors_still_exist
|
2BP01
|
dependent objects still exist
dependent_objects_still_exist
cannot drop table customers because other objects depend on it
DETAIL: constraint orders_customer_id_fkey on table orders depends on table customers
HINT: Use DROP ... CASCADE to drop the dependent objects too.
|
Invalid Transaction Termination
| Code | Meaning |
|---|---|
2D000
|
invalid transaction termination
invalid_transaction_termination
invalid transaction termination
|
SQL Routine Exception
| Code | Meaning |
|---|---|
2F000
|
sql_routine_exception
|
2F005
|
function_executed_no_return_statement
|
2F002
|
modifying_sql_data_not_permitted
|
2F003
|
prohibited_sql_statement_attempted
|
2F004
|
reading_sql_data_not_permitted
|
Invalid Cursor Name
| Code | Meaning |
|---|---|
34000
|
invalid_cursor_name
|
External Routine Exception
| Code | Meaning |
|---|---|
38000
|
external_routine_exception
|
38001
|
containing_sql_not_permitted
|
38002
|
modifying_sql_data_not_permitted
|
38003
|
prohibited_sql_statement_attempted
|
38004
|
reading_sql_data_not_permitted
|
External Routine Invocation Exception
| Code | Meaning |
|---|---|
39000
|
external_routine_invocation_exception
|
39001
|
invalid_sqlstate_returned
|
39004
|
null_value_not_allowed
|
39P01
|
trigger_protocol_violated
|
39P02
|
srf_protocol_violated
|
39P03
|
event_trigger_protocol_violated
|
Savepoint Exception
| Code | Meaning |
|---|---|
3B000
|
savepoint_exception
|
3B001
|
invalid savepoint specification
invalid_savepoint_specification
savepoint "before_update" does not exist
|
Invalid Catalog Name
| Code | Meaning |
|---|---|
3D000
|
database does not exist
invalid_catalog_name
database "shop" does not exist
|
Invalid Schema Name
| Code | Meaning |
|---|---|
3F000
|
schema does not exist
invalid_schema_name
schema "sales" does not exist
|
Transaction Rollback
| Code | Meaning |
|---|---|
40000
|
transaction_rollback
|
40002
|
transaction_integrity_constraint_violation
|
40001
|
could not serialize access
serialization_failure
could not serialize access due to concurrent update
|
40003
|
statement_completion_unknown
|
40P01
|
deadlock detected
deadlock_detected
deadlock detected
DETAIL: Process 1234 waits for ShareLock on transaction 5678; blocked by process 4321.
Process 4321 waits for ShareLock on transaction 8765; blocked by process 1234.
|
Syntax Error or Access Rule Violation
| Code | Meaning |
|---|---|
42000
|
syntax_error_or_access_rule_violation
|
42601
|
syntax error at or near
syntax_error
syntax error at or near "FROM"
LINE 1: SELECT id, name, FROM users;
^
|
42501
|
permission denied
insufficient_privilege
permission denied for table orders
|
42846
|
cannot coerce
cannot_coerce
cannot cast type integer to uuid
|
42803
|
column must appear in the GROUP BY clause
grouping_error
column "o.customer_id" must appear in the GROUP BY clause or be used in an aggregate function
|
42P20
|
windowing_error
|
42P19
|
invalid_recursion
|
42830
|
invalid foreign key
invalid_foreign_key
there is no unique constraint matching given keys for referenced table "customers"
|
42602
|
invalid_name
|
42622
|
name_too_long
|
42939
|
reserved_name
|
42804
|
datatype mismatch
datatype_mismatch
column "created_at" is of type timestamp with time zone but expression is of type integer
HINT: You will need to rewrite or cast the expression.
|
42P18
|
could not determine data type of parameter
indeterminate_datatype
could not determine data type of parameter $1
|
42P21
|
collation_mismatch
|
42P22
|
indeterminate_collation
|
42809
|
wrong_object_type
|
428C9
|
generated_always
|
42703
|
column does not exist
undefined_column
column "emial" does not exist
LINE 1: SELECT emial FROM users;
^
HINT: Perhaps you meant to reference the column "users.email".
|
42883
|
function does not exist
undefined_function
function lower(integer) does not exist
LINE 1: SELECT lower(42);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
42P01
|
relation does not exist
undefined_table
relation "orders" does not exist
LINE 1: SELECT * FROM orders;
^
|
42P02
|
there is no parameter
undefined_parameter
there is no parameter $1
|
42704
|
undefined object
undefined_object
type "jsonbb" does not exist
|
42701
|
duplicate_column
|
42P03
|
duplicate_cursor
|
42P04
|
database already exists
duplicate_database
database "shop" already exists
|
42723
|
duplicate_function
|
42P05
|
duplicate_prepared_statement
|
42P06
|
schema already exists
duplicate_schema
schema "sales" already exists
|
42P07
|
relation already exists
duplicate_table
relation "orders" already exists
|
42712
|
duplicate_alias
|
42710
|
duplicate object
duplicate_object
role "app" already exists
|
42702
|
column reference is ambiguous
ambiguous_column
column reference "id" is ambiguous
LINE 1: SELECT id FROM orders JOIN customers ON customers.id = orders.customer_id;
^
|
42725
|
ambiguous_function
|
42P08
|
ambiguous_parameter
|
42P09
|
ambiguous_alias
|
42P10
|
invalid column reference
invalid_column_reference
there is no unique or exclusion constraint matching the ON CONFLICT specification
|
42611
|
invalid_column_definition
|
42P11
|
invalid_cursor_definition
|
42P12
|
invalid_database_definition
|
42P13
|
invalid_function_definition
|
42P14
|
invalid_prepared_statement_definition
|
42P15
|
invalid_schema_definition
|
42P16
|
invalid_table_definition
|
42P17
|
invalid_object_definition
|
WITH CHECK OPTION Violation
| Code | Meaning |
|---|---|
44000
|
with_check_option_violation
|
Insufficient Resources
| Code | Meaning |
|---|---|
53000
|
insufficient_resources
|
53100
|
disk full
disk_full
could not extend file "base/16384/16397": No space left on device
HINT: Check free disk space.
|
53200
|
out of memory
out_of_memory
out of memory
DETAIL: Failed on request of size 1048576 in memory context "ExecutorState".
|
53300
|
too many connections
too_many_connections
sorry, too many clients already
|
53400
|
configuration_limit_exceeded
|
Program Limit Exceeded
| Code | Meaning |
|---|---|
54000
|
program limit exceeded
program_limit_exceeded
index row size 3200 exceeds btree version 4 maximum 2704 for index "documents_body_idx"
DETAIL: Index row references tuple (12,3) in relation "documents".
HINT: Values larger than 1/3 of a buffer page cannot be indexed.
Consider a function index of an MD5 hash of the value, or use full text indexing.
|
54001
|
statement_too_complex
|
54011
|
too_many_columns
|
54023
|
too_many_arguments
|
Object Not In Prerequisite State
| Code | Meaning |
|---|---|
55000
|
object not in prerequisite state
object_not_in_prerequisite_state
currval of sequence "orders_id_seq" is not yet defined in this session
|
55006
|
object in use
object_in_use
database "shop" is being accessed by other users
DETAIL: There is 1 other session using the database.
|
55P02
|
cant_change_runtime_param
|
55P03
|
lock not available
lock_not_available
could not obtain lock on row in relation "orders"
|
55P04
|
unsafe_new_enum_value_usage
|
Operator Intervention
| Code | Meaning |
|---|---|
57000
|
operator_intervention
|
57014
|
canceling statement
query_canceled
canceling statement due to statement timeout
|
57P01
|
terminating connection due to administrator
admin_shutdown
terminating connection due to administrator command
|
57P02
|
crash_shutdown
|
57P03
|
cannot connect now
cannot_connect_now
the database system is starting up
|
57P04
|
database_dropped
|
57P05
|
idle_session_timeout
|
System Error (errors external to PostgreSQL itself)
| Code | Meaning |
|---|---|
58000
|
system_error
|
58030
|
io_error
|
58P01
|
undefined file
undefined_file
could not open file "/tmp/orders.csv" for reading: No such file or directory
|
58P02
|
duplicate_file
|
58P03
|
file_name_too_long
|
Configuration File Error
| Code | Meaning |
|---|---|
F0000
|
config_file_error
|
F0001
|
lock_file_exists
|
Foreign Data Wrapper Error (SQL/MED)
| Code | Meaning |
|---|---|
HV000
|
fdw_error
|
HV005
|
fdw_column_name_not_found
|
HV002
|
fdw_dynamic_parameter_value_needed
|
HV010
|
fdw_function_sequence_error
|
HV021
|
fdw_inconsistent_descriptor_information
|
HV024
|
fdw_invalid_attribute_value
|
HV007
|
fdw_invalid_column_name
|
HV008
|
fdw_invalid_column_number
|
HV004
|
fdw_invalid_data_type
|
HV006
|
fdw_invalid_data_type_descriptors
|
HV091
|
fdw_invalid_descriptor_field_identifier
|
HV00B
|
fdw_invalid_handle
|
HV00C
|
fdw_invalid_option_index
|
HV00D
|
fdw_invalid_option_name
|
HV090
|
fdw_invalid_string_length_or_buffer_length
|
HV00A
|
fdw_invalid_string_format
|
HV009
|
fdw_invalid_use_of_null_pointer
|
HV014
|
fdw_too_many_handles
|
HV001
|
fdw_out_of_memory
|
HV00P
|
fdw_no_schemas
|
HV00J
|
fdw_option_name_not_found
|
HV00K
|
fdw_reply_handle
|
HV00Q
|
fdw_schema_not_found
|
HV00R
|
fdw_table_not_found
|
HV00L
|
fdw_unable_to_create_execution
|
HV00M
|
fdw_unable_to_create_reply
|
HV00N
|
fdw_unable_to_establish_connection
|
PL/pgSQL Error
| Code | Meaning |
|---|---|
P0000
|
plpgsql_error
|
P0001
|
raise exception
raise_exception
insufficient funds for account 42
|
P0002
|
no_data_found
|
P0003
|
too_many_rows
|
P0004
|
assert_failure
|
Internal Error
| Code | Meaning |
|---|---|
XX000
|
internal error
internal_error
cache lookup failed for relation 16397
|
XX001
|
data corrupted
data_corrupted
invalid page in block 1234 of relation base/16384/16397
|
XX002
|
index_corrupted
|
Other databases
A faster way to work with PostgreSQL
SQLly is a native SQL client for macOS, Windows and Linux with schema-aware IntelliSense and guardrails for risky statements.