Friday, February 5, 2016

Netezza: ALTER TABLE to MODIFY a column datatype



At Netezza, you may NOT change datatype of a column with ALTER TABLE xxxx MODIFY COLUMN COL_1:

Allowed only to:
  • Change a column name
  • Change a column default value
  • Only increase length of a VARCHAR column (not to decrease).

--- FAIL: Changing DATE to TIMESTAMP
/*ERROR [HY000] ERROR:  ALTER TABLE: only varchar fields can be modified */
alter table XXX MODIFY COLUMN COL TIMESTAMP;

--- FAIL: Changing VARCHAR(5) to VARCHAR(4)
/*ERROR [HY000] ERROR:  ALTER TABLE: varchar field size can only be increased */
alter table XXX MODIFY COLUMN COL3 VARCHAR(4 );


--- SUCCESSChanging VARCHAR(3) to VARCHAR(5)
/* Start time 3/28/2014 11:25:00 AM, end time 3/28/2014 11:25:00 AM. */
/* Duration 0.0624004 sec. */
alter table XXX MODIFY COLUMN COL3 VARCHAR(5 );

Refer:

3 comments: