ALTER TABLE
Add, drop, rename, and reorder columns; widen types; manage schema evolution.
ALTER TABLE in Krishiv is supported primarily for Iceberg tables. The operations are metadata-only for the most part — no data rewrite required.
Supported operations
| Operation | SQL form | What it does |
|---|---|---|
| Add column | ALTER TABLE t ADD COLUMN c TYPE | Metadata-only. New column is NULL for existing rows. |
| Drop column | ALTER TABLE t DROP COLUMN c | Metadata-only. Readers return NULL. |
| Rename column | ALTER TABLE t RENAME COLUMN old TO new | Metadata-only. Existing queries break. |
| Reorder column | ALTER TABLE t ALTER COLUMN c AFTER other | Metadata-only. Storage layout unchanged. |
| Widen type | ALTER TABLE t ALTER COLUMN c TYPE NEW | Metadata-only if the new type is a superset (e.g. INT → BIGINT, FLOAT → DOUBLE). |
| Set comment | ALTER TABLE t ALTER COLUMN c COMMENT '...' | Metadata-only. |
| Add partition spec | ALTER TABLE t ADD PARTITION FIELD bucket(16, id) | Metadata-only. New writes use the new spec; old data is not rewritten. |
Examples
-- Add a new column (NULL for existing rows)
ALTER TABLE orders ADD COLUMN region VARCHAR;
-- Rename safely (will break old queries — deploy in lockstep)
ALTER TABLE orders RENAME COLUMN amt TO amount;
-- Widen a type (INT → BIGINT is metadata-only)
ALTER TABLE orders ALTER COLUMN user_id TYPE BIGINT;
-- Drop a column
ALTER TABLE orders DROP COLUMN legacy_col;
Compatibility modes
Set the compatibility mode on the table to control which operations are allowed:
| Mode | Description |
|---|---|
backward (default) | Old readers can read new data. Add/drop/widen are OK. |
forward | New readers can read old data. Drop/widen are OK. |
full | Both. Most restrictive. |
none | No checks. Use only for development. |
Branches and tags for risky changes
For destructive experiments, branch first:
-- Create a branch at the current main snapshot
CALL system.create_branch('orders', 'experiment', main_ref);
-- Run the migration on the branch
ALTER TABLE orders_branch ADD COLUMN region VARCHAR;
-- Inspect via time-travel
SELECT * FROM orders FOR SYSTEM_TIME AS OF 'experiment';
-- Promote or drop
CALL system.fast_forward('orders', 'experiment', main_ref);
CALL system.drop_branch('orders', 'experiment');
Unsupported operations
- Narrowing a column type (DOUBLE → FLOAT).
- Renaming a partition column.
- Changing the partition spec on existing data without a re-partition job.