How to increase column size in Redshift database tables

0 min read 173 words

It is only possible to alter VARCHAR columns, and only under the following circumstances:

  • You can not alter a column with compression encodings BYTEDICT, RUNLENGTH, TEXT255, or TEXT32K.
  • You can not decrease the size less than the maximum size of existing data.
  • You can not alter columns with default values.
  • You can not alter columns with UNIQUE, PRIMARY KEY, or FOREIGN KEY.
  • You can not alter columns inside a multi-statement block (BEGIN...END).

SQL to increase the size of (Redshift Alter Table)

It’s very simple to perform a Redshift Alter Table command to alter the column length, or alter the column varchar length:

ALTER TABLE <table_name> ALTER COLUMN <column_name> type varchar(300);

The above command will increase column size to Redshift tables and alter the column length, or column size as required.

There is no TEXT column size in Redshift, so you can go to a maximum of 65535, or simply specify the max alias.

For example:

ALTER TABLE <table_name> ALTER COLUMN <column_name> type varchar(65535);

-- or

ALTER TABLE <table_name> ALTER COLUMN <column_name> type varchar(max);
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags