Manage Tables
Manage columns
Add, update, and remove columns on a PostgreSQL table in Fakebase Studio.
Open a table, then choose the Columns tab. You can add, edit, and remove columns without writing SQL.
The same changes can be pasted into the SQL editor. The examples below continue the orders table from Manage Tables.
Add a column
- Open a table and go to Columns.
- Choose Add column.
- Set the name, type, default, and constraints.
- Confirm.
You can also attach a foreign key while adding the column. See Relations.
ALTER TABLE public.orders
ADD COLUMN status text NOT NULL DEFAULT 'pending';
Edit a column
Open the column row menu and choose Edit column. You can change the name, type, default, and constraints such as primary key, nullable, unique, and CHECK.
ALTER TABLE public.orders
RENAME COLUMN status TO order_status;
ALTER TABLE public.orders
ALTER COLUMN order_status SET DEFAULT 'open',
ALTER COLUMN order_status SET NOT NULL;
ALTER TABLE public.orders
ADD CONSTRAINT orders_order_status_check
CHECK (order_status IN ('open', 'pending', 'paid', 'cancelled'));
Remove a column
Open the column row menu and choose Remove column. Fakebase also removes constraints that belong only to that column.
You cannot remove the last column on a table, a column that is part of a composite constraint, or a column referenced by another table's foreign key.
ALTER TABLE public.orders
DROP COLUMN order_status;