P0002
Read PG 18 manual ↗no_data_found
- SQLSTATE
- P0002
- Condition name
- no_data_found
- Class
- PL/pgSQL Error
- Source macro
- ERRCODE_NO_DATA_FOUND
- Evidence
- Source path confirmed
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
At a glance
P0002 is PL/pgSQL no_data_found. Fixed paths include the strict-query ERROR text and a separate tablespace NOTICE path; it does not mean every SELECT returning zero rows.
Meaning
A fixed PL/pgSQL strict-query path reports query returned no rows and may attach parameters: %s detail, while a tablespace path uses the same SQLSTATE for the NOTICE no matching relations in tablespace "%s" found. It does not mean every SELECT returning zero rows.
Diagnosis
Separate strict-query ERROR from the tablespace NOTICE by message and severity. A normal zero-row SELECT is not enough to establish P0002.
Response
Handle the strict no-row case explicitly. For the tablespace NOTICE, verify whether the empty match is intended; if it is, no repair is required, otherwise correct the target before continuing. Do not automatically replay a zero-row operation.
Versions
The locked catalogue records this condition from 8.2.0 in the listed formal snapshots and 19beta3; fixed source coverage is PostgreSQL 18.6.
Sources
See the fixed pl_exec.c and tablecmds.c paths alongside the structured evidence record.
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
P0002 is no_data_found in PostgreSQL-specific Class P0.
Method: Read the fixed definition row.
PL/pgSQL fixed paths report P0002 with `query returned no rows` when the checked query produced no row; optional detail is `parameters: %s` when strict-parameter printing is enabled.
Method: Read both pl_exec report groups and their conditional errdetail.
A core tablespace path also uses P0002 at NOTICE level for no matching relations in a tablespace.
Method: Compare the literal NOTICE level with the PL/pgSQL ERROR paths.
P0002 is not a synonym for every SELECT that happens to return zero rows; the operation and enforcing path determine whether it is raised.
Method: Read the surrounding target-row and strict checks.
Limits: No runtime case was executed in this batch.
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 raw/calls/REL_18_6.jsonl· ·- src/pl/plpgsql/src/pl_exec.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/commands/tablecmds.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7
Message templates
ERROR · message.no-rows
Primary
query returned no rows
Detail
parameters: %s
NOTICE · message.no-tablespace-relations
Primary
no matching relations in tablespace "%s" found
Reproduction & repair cases
No reproduction case is attached to this condition.
Recorded runtime evidence
No runtime observation is attached to this entry.
Definition snapshot: english-manuals:238e1443806e5437d55b4763241… · English manual source