54011
PostgreSQLERRORNotableProgram Limit ExceededHIGH confidence

too many columns

What this means

SQLSTATE 54011 is raised when a table definition or query result has more columns than the maximum allowed by Postgres. The default maximum is 1,600 columns per table.

Why it happens
  1. 1CREATE TABLE with more than 1,600 columns
  2. 2A query SELECT that generates too many columns (e.g., SELECT * from a very wide join)
How to reproduce

Creating a table with more than 1,600 columns.

trigger — this will error
trigger — this will error
-- CREATE TABLE with 1,601+ columns

expected output

ERROR:  tables can have at most 1600 columns

Fix 1

Redesign the schema using normalisation or JSONB for wide data

WHEN When a table genuinely needs more than 1,600 columns.

Redesign the schema using normalisation or JSONB for wide data
-- Use JSONB for semi-structured wide data:
ALTER TABLE wide_table ADD COLUMN attributes JSONB;
-- Store the extra columns as keys in the JSONB object

Why this works

JSONB can store arbitrary key-value pairs, effectively allowing unlimited attributes without hitting the column limit.

Fix 2

Split the wide table into multiple related tables

WHEN When columns can be grouped by domain.

Why this works

Normalise the wide table into multiple tables joined by a common primary key. Each table stays within the 1,600 column limit.

What not to do

Create tables with close to 1,600 columns

Wide tables have poor performance and are difficult to maintain. Redesign the schema instead.

Sources
Official documentation ↗

Class 54 — Program Limit Exceeded

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors