Skip to content

P0002 — no_data_found

Source-backed reference for PostgreSQL SQLSTATE P0002.

P0002

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.

Field Value
SQLSTATE P0002
Condition no_data_found
Status active
Known present by 8.2.0
Locked snapshots 9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3
Macros ERRCODE_NO_DATA_FOUND
Aliases

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.

P0003, P0004, 02000

Sources

See the fixed pl_exec.c and tablecmds.c paths alongside the structured evidence record.