ALTER TABLE ... ADD COLUMN adds a new column to an existing ParadeDB table without recreating the table.
Add new data points—like last_login—to production tables without full table rebuilds. The command is transactional and keeps existing data intact.
Run ALTER TABLE table_name ADD [COLUMN] column_name data_type [options];
.The keyword COLUMN is optional and purely for readability.
ALTER TABLE Customers ADD COLUMN phone VARCHAR(20);
instantly creates a phone field for every customer.
Yes—use DEFAULT
then back-fill automatically: ALTER TABLE Orders ADD COLUMN status TEXT NOT NULL DEFAULT 'pending';
.
PostgreSQL stores column order but you can’t specify position.Use SELECT *
with explicit column list or view.
Combine with commas: ALTER TABLE Products ADD COLUMN weight NUMERIC, ADD COLUMN dimensions TEXT;
.
ALTER TABLE OrderItems ADD COLUMN product_id INT REFERENCES Products(id);
enforces referential integrity.
1) Always test in staging. 2) Add DEFAULT before NOT NULL to avoid table rewrite.3) Wrap in transactions for rollbacks.
Use ALTER TABLE table_name DROP COLUMN column_name;
in the same transaction if needed.
Yes. The operation is metadata-only unless a NOT NULL constraint without DEFAULT forces a full rewrite—avoid that pitfall.
Metadata-only adds are fast and non-blocking.Adding NOT NULL without a default rewrites the table and can block.
Yes—add the column nullable, run an UPDATE
to populate, then set NOT NULL.
.
Simple metadata-only adds do not. Full rewrites from NOT NULL without DEFAULT do.
Yes—use GENERATED ALWAYS AS (expression) STORED
in PostgreSQL 12+ and ParadeDB inherits the feature.