SQLSTATE 54000 ERROR Class 54: Program Limit Exceeded

program_limit_exceeded target lists can have at most N entries — 54000

PostgreSQL error "target lists can have at most N entries" (SQLSTATE 54000): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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

  1. Select only the columns you need instead of SELECT *.
  2. Split a very wide result into multiple narrower queries.
  3. Reconsider the data model if rows truly need this many attributes.

Related & next steps

Reference: PostgreSQL 18 Appendix K “PostgreSQL Limits”.

Was this helpful?