54001 \u2014 statement_too_complex
54001 covers a statement that exceeds a planner, parser, or execution-stack limit. Fixed paths include the 4096 grouping-set ceiling and maxstackdepth enforcement.
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
- Program Limit Exceeded
- condition name
- statement_too_complex
- lang
- en
- sqlstate
- 54001
Definition PG 18
54001
At a glance {#at-a-glance}
54001 covers a statement that exceeds a planner, parser, or execution-stack limit. Fixed paths include the 4096 grouping-set ceiling and max_stack_depth enforcement.
Meaning {#meaning}
The source separates a structural query limit (too many grouping sets present (maximum 4096)) from recursive execution depth (stack depth limit exceeded) with a hint naming max_stack_depth. They need different repairs: reducing query structure is not the same as changing a stack setting.
Diagnosis {#diagnosis}
Preserve the message and phase. For grouping sets, count the generated grouping sets and simplify the query. For stack depth, inspect recursive SQL/function expansion and compare the setting with the platform stack limit before changing it.
Response {#response}
Rewrite or decompose a structurally excessive statement. For stack depth, remove unintended recursion or reduce nesting; change max_stack_depth only after checking the operating-system stack allowance and operational policy. If this ERROR occurs inside an explicit transaction, use ROLLBACK or ROLLBACK TO SAVEPOINT before retrying; in autocommit, retry only after the statement or stack setting is corrected. The GUC rlimit check validates a SET or configuration value against the platform allowance; a failed SET still follows the transaction context that issued it. Validate the rewritten statement rather than automatically replaying it.
Versions {#versions}
The locked catalogue records this condition from 7.4; cited parser and stack-depth paths are PostgreSQL 18.6 source. No complexity limit was forced.
Related {#related}
Sources {#sources}
src/backend/parser/parse_agg.c#L1166-L1172
src/backend/utils/misc/stack_depth.c#L100-L105
src/backend/utils/misc/stack_depth.c#L156-L168
The structured evidence record records fixed messages and the source/runtime boundary.
Compare versions
SQLSTATE evidence and recorded runtime versions
claims · identity
{
"claim_id": "identity",
"limits": "",
"method": "Read fixed definition.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "54001 is statement_too_complex in SQLSTATE Class 54."
}claims · resolved-paths
{
"claim_id": "resolved-paths",
"limits": "Source confirmation is not natural runtime.",
"method": "Read complete fixed source contexts.",
"position": 1,
"runtime": [],
"sources": [
"src.path.0",
"src.path.1",
"src.path.2"
],
"statement": "The cited PostgreSQL 18.6 source paths support the representative resource and object-state mechanisms described."
}claims · stack-platform-guard
{
"claim_id": "stack-platform-guard",
"limits": "",
"method": "Read the complete stack-depth error and GUC check hooks.",
"position": 2,
"runtime": [],
"sources": [
"src.path.1",
"src.path.2"
],
"statement": "The max_stack_depth GUC check rejects a value above the platform stack rlimit and points to increasing the platform limit, while recursive checks emit 54001 before stack overflow."
}claims · history
{
"claim_id": "history",
"limits": "",
"method": "Use catalogue boundary.",
"position": 3,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "The locked catalogue records 54001 from 7.4; that boundary does not prove exact implementation introduction."
}messages · message.0
{
"limits": "",
"message_id": "message.0",
"path": "",
"position": 0,
"raw": {
"id": "message.0",
"primary_template": "too many grouping sets present (maximum 4096)",
"severity_source": "ERROR",
"sources": [
"src.path.0"
],
"sqlstate": "54001"
},
"severity": "ERROR",
"sources": [
"src.path.0"
],
"templates": [
{
"kind": "primary",
"literal": "too many grouping sets present (maximum 4096)",
"position": 0,
"role": "",
"template": "too many grouping sets present (maximum 4096)"
}
]
}messages · message.1
{
"limits": "",
"message_id": "message.1",
"path": "",
"position": 1,
"raw": {
"hint_template": "Increase the configuration parameter \"max_stack_depth\" (currently %dkB), after ensuring the platform stack depth limit is adequate.",
"id": "message.1",
"primary_template": "stack depth limit exceeded",
"severity_source": "ERROR",
"sources": [
"src.path.1"
],
"sqlstate": "54001"
},
"severity": "ERROR",
"sources": [
"src.path.1"
],
"templates": [
{
"kind": "primary",
"literal": "stack depth limit exceeded",
"position": 0,
"role": "",
"template": "stack depth limit exceeded"
},
{
"kind": "hint",
"literal": "Increase the configuration parameter \"max_stack_depth\" (currently kB), after ensuring the platform stack depth limit is adequate.",
"position": 1,
"role": "",
"template": "Increase the configuration parameter \"max_stack_depth\" (currently %dkB), after ensuring the platform stack depth limit is adequate."
}
]
}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#L417"
}sources · src.path.0
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/parser/parse_agg.c",
"position": 1,
"sha256": "6e80a805fddbfc9c7e0f3047b348bf992a20c99f16ce7fee89c7067753027f72",
"source_id": "src.path.0",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/parse_agg.c#L1166"
}sources · src.path.1
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/misc/stack_depth.c",
"position": 2,
"sha256": "ed87e94a4f73600983230aca3a4c1869d3b9cbb7c83ec36a6bbd7e403925e920",
"source_id": "src.path.1",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/misc/stack_depth.c#L100"
}sources · src.path.2
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/utils/misc/stack_depth.c",
"position": 3,
"sha256": "ed87e94a4f73600983230aca3a4c1869d3b9cbb7c83ec36a6bbd7e403925e920",
"source_id": "src.path.2",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/misc/stack_depth.c#L156"
}Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · english-manuals:93ffc7497d2d56bc345c23ed69b07466e629a4a9c3001ce85644a43ab1d151ef
Text language: en · english-manuals:93ffc7497d2d56bc345c23ed69b07466e629a4a9c3001ce85644a43ab1d151ef