How to resolve ‘ALTER TABLE ALTER COLUMN cannot run inside a transaction block’ in Redshift

You might encounter the below error while trying to modify a column in Redshift database from SQL Workbench.

[Amazon](500310) Invalid operation: ALTER TABLE ALTER COLUMN cannot run inside a transaction block;
1 statement failed. 

You can overcome this error by turning Autocommit ON before running the alter table statement. You may later turn the Autocommint OFF after modifying the column.

Example:

set autocommit on;
alter table schemaname.tablename alter column columnname type varchar(2000);
set autocommit off;

See also  How to create a group and add users to group in Redshift