ALTER TABLE … ALTER COLUMN … TYPE lets you convert a column to a new data type in Amazon Redshift.
Run ALTER TABLE table_name ALTER COLUMN column_name TYPE new_data_type
. Optionally add USING
to cast existing values, plus COLLATE
or ENCODE
. The statement rewrites the column; ensure backups and free disk space.
Confirm no active loads, the column is not a DISTKEY
/SORTKEY
, and you hold ALTER
privilege. Verify the new type is compatible or supply an explicit cast.
Add a USING
clause: ALTER TABLE Orders ALTER COLUMN total_amount TYPE DECIMAL(12,2) USING total_amount::DECIMAL(12,2);
. Without USING
, Redshift attempts an implicit cast and fails if unsafe.
1. Pause ETL jobs.
2. ALTER TABLE Orders ALTER COLUMN total_amount TYPE DECIMAL(12,2) ENCODE az64;
3. Verify with SELECT * FROM SVV_COLUMNS WHERE table_name='orders' AND column_name='total_amount';
4. Resume jobs after completion.
Query SVV_COLUMNS
or pg_table_def
to confirm the new data_type and encoding. Run test selects to ensure application logic still behaves correctly.
Choose the smallest precise type to reduce I/O. Always specify column encoding after the change. Batch multiple column alterations in one transaction but monitor maintenance windows.
Long locks, insufficient disk space, or failed casts. Monitor STL_ALTER_TABLE
for progress and errors. Abort quickly if disk usage spikes.
Yes, if all values are numeric. Use USING column::INTEGER
to avoid conversion errors.
Redshift takes an exclusive lock during the rewrite. Queries wait; inserts/updates fail. Schedule the change during low-traffic windows.