too many columns
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.
- 1CREATE TABLE with more than 1,600 columns
- 2A query SELECT that generates too many columns (e.g., SELECT * from a very wide join)
Creating a table with more than 1,600 columns.
-- 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.
-- 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.
✕ Create tables with close to 1,600 columns
Wide tables have poor performance and are difficult to maintain. Redesign the schema instead.
Class 54 — Program Limit Exceeded
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev