54001
Read PG 18 manual ↗statement_too_complex
- SQLSTATE
- 54001
- Condition name
- statement_too_complex
- Class
- Program Limit Exceeded
- Source macro
- ERRCODE_STATEMENT_TOO_COMPLEX
- Evidence
- Source path confirmed
English SQLSTATE atlas: authored explanations and source/runtime evidence are separate from the manual definitions. View source ↗
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
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
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
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
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.
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.
Source evidence
Evidence belongs to the frozen source and runtime versions listed here. It is not a runtime verification of the selected manual version.
The cited PostgreSQL 18.6 source paths support the representative resource and object-state mechanisms described.
Method: Read complete fixed source contexts.
Limits: Source confirmation is not natural runtime.
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.
Method: Read the complete stack-depth error and GUC check hooks.
The locked catalogue records 54001 from 7.4; that boundary does not prove exact implementation introduction.
Method: Use catalogue boundary.
- src/backend/utils/errcodes.txt · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/parser/parse_agg.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/misc/stack_depth.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7 - src/backend/utils/misc/stack_depth.c · REL_18_6 ·
724edf9bde9d356724ad384a2e196edc3c9f80f7
Message templates
ERROR · message.0
Primary
too many grouping sets present (maximum 4096)
ERROR · message.1
Primary
stack depth limit exceeded
Hint
Increase the configuration parameter "max_stack_depth" (currently %dkB), after ensuring the platform stack depth limit is adequate.
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:d60729725aa8adf5fe33e7e1b8c… · English manual source