P0002 — no_data_found
P0002 is PL/pgSQL nodatafound. Fixed paths include the strict-query ERROR text and a separate tablespace NOTICE path; it does not mean every SELECT returning zero rows.
English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.
Reading PG 18·Select a recorded version
- aliases
- Unknown
- class name
- PL/pgSQL Error
- condition name
- no_data_found
- lang
- en
- sqlstate
- P0002
Definition PG 18
P0002
At a glance {#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 {#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 {#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 {#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 {#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.
Related {#related}
Sources {#sources}
See the fixed pl_exec.c and tablecmds.c paths alongside the structured evidence record.
Compare versions
SQLSTATE evidence and recorded runtime versions
claims · identity
{
"claim_id": "identity",
"limits": "",
"method": "Read the fixed definition row.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "P0002 is no_data_found in PostgreSQL-specific Class P0."
}claims · strict-query
{
"claim_id": "strict-query",
"limits": "",
"method": "Read both pl_exec report groups and their conditional errdetail.",
"position": 1,
"runtime": [],
"sources": [
"src.path.plpgsql"
],
"statement": "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."
}claims · notice-path
{
"claim_id": "notice-path",
"limits": "",
"method": "Compare the literal NOTICE level with the PL/pgSQL ERROR paths.",
"position": 2,
"runtime": [],
"sources": [
"src.path.tablespace"
],
"statement": "A core tablespace path also uses P0002 at NOTICE level for no matching relations in a tablespace."
}claims · scope
{
"claim_id": "scope",
"limits": "No runtime case was executed in this batch.",
"method": "Read the surrounding target-row and strict checks.",
"position": 3,
"runtime": [],
"sources": [
"src.path.plpgsql"
],
"statement": "P0002 is not a synonym for every SELECT that happens to return zero rows; the operation and enforcing path determine whether it is raised."
}messages · message.no-rows
{
"limits": "",
"message_id": "message.no-rows",
"path": "",
"position": 0,
"raw": {
"detail_template": "parameters: %s",
"id": "message.no-rows",
"primary_template": "query returned no rows",
"severity_source": "ERROR",
"sources": [
"src.path.plpgsql"
],
"sqlstate": "P0002"
},
"severity": "ERROR",
"sources": [
"src.path.plpgsql"
],
"templates": [
{
"kind": "primary",
"literal": "query returned no rows",
"position": 0,
"role": "",
"template": "query returned no rows"
},
{
"kind": "detail",
"literal": "parameters:",
"position": 1,
"role": "",
"template": "parameters: %s"
}
]
}messages · message.no-tablespace-relations
{
"limits": "",
"message_id": "message.no-tablespace-relations",
"path": "",
"position": 1,
"raw": {
"id": "message.no-tablespace-relations",
"primary_template": "no matching relations in tablespace \"%s\" found",
"severity_source": "NOTICE",
"sources": [
"src.path.tablespace"
],
"sqlstate": "P0002"
},
"severity": "NOTICE",
"sources": [
"src.path.tablespace"
],
"templates": [
{
"kind": "primary",
"literal": "no matching relations in tablespace \" \" found",
"position": 0,
"role": "",
"template": "no matching relations in tablespace \"%s\" found"
}
]
}sources · src.errcodes.18.6
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/errcodes.txt",
"position": 0,
"sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
"source_id": "src.errcodes.18.6",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L492"
}sources · src.calls.REL_18_6
{
"commit": "",
"docs_url": "",
"kind": "local_artifact",
"location": "",
"path": "raw/calls/REL_18_6.jsonl",
"position": 1,
"sha256": "9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf",
"source_id": "src.calls.REL_18_6",
"tag": "",
"url": ""
}sources · src.path.plpgsql
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/pl/plpgsql/src/pl_exec.c",
"position": 2,
"sha256": "0df3c70a6bccf6dddf443fb99e152a16a67009827c44a820597e98e585cb8b20",
"source_id": "src.path.plpgsql",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/pl/plpgsql/src/pl_exec.c#L4384-L4387"
}sources · src.path.tablespace
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/commands/tablecmds.c",
"position": 3,
"sha256": "422dc8e833df4940755973c757e338295822ba3e4c7266c40669f49f96eb15a9",
"source_id": "src.path.tablespace",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/tablecmds.c#L17162-L17166"
}Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · english-manuals:b3b55af9d3e0e9ccc8e3805da12d3343a97bedefe383dc704a14e19d40df2061
Text language: en · english-manuals:b3b55af9d3e0e9ccc8e3805da12d3343a97bedefe383dc704a14e19d40df2061