Diagnostic Queries
Symptoms
A query’s select list (or an INSERT/UPDATE column list) had more entries than PostgreSQL allows — the hard limit derived from MaxTupleAttributeNumber (1664). PostgreSQL raises SQLSTATE 54000 (program_limit_exceeded).
- Triggered by extremely wide SELECT or INSERT column lists.
- Often from generated SQL or
SELECT *across many joined wide tables. - The maximum is 1664 target entries.
What the server log shows
ERROR: target lists can have at most 1664 entries
Why PostgreSQL raises this — what the manual says
As Appendix K PostgreSQL Limitations explains:
A query’s target list (its SELECT output columns, or the columns of a row being projected) exceeded the fixed internal maximum of 1664 entries; reduce the number of result columns, for example by selecting fewer expressions or splitting the query.
A tuple can hold at most 1664 attributes, so a result target list is bounded by the same limit. A query producing more entries cannot form a valid tuple and PostgreSQL aborts with 54000.
Common causes
- Generated SQL selecting an enormous number of columns/expressions.
- Joining many wide tables with
SELECT *. - Building pivots/crosstabs with too many output columns.
How to fix it
- Select only the columns you need instead of
SELECT *. - Split a very wide result into multiple narrower queries.
- Reconsider the data model if rows truly need this many attributes.
Related & next steps
Reference: PostgreSQL 18 Appendix K “PostgreSQL Limits”.
Thanks — noted. This helps keep the database accurate.