Alter table to change the datatype of one column

Moderator: NorbertKrupa

Post Reply
Jess.mic
Newbie
Newbie
Posts: 15
Joined: Tue Jun 11, 2013 11:02 pm

Alter table to change the datatype of one column

Post by Jess.mic » Mon Jul 15, 2013 5:00 pm

How can I alter the table to change the datatype of one column.

For e.g. I need to change the datatype of column from varchar to integer. How can I change that??

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: Alter table to change the datatype of one column

Post by id10t » Mon Jul 15, 2013 6:58 pm

Hi!


>> How can I alter the table to change the datatype of one column.
VARCHAR to INTEGER? You can't, coz' it require storage reorganization.
Changing a column's data type

You can changes a table column's data type for any type whose conversion does not require storage reorganization. For example, the following types are the conversions that Vertica supports:

Binary types — expansion and contraction but cannot convert between BINARY and VARBINARY types.
Character types — all conversions allowed, even between CHAR and VARCHAR
Exact numeric types — INTEGER, INT, BIGINT, TINYINT, INT8, SMALLINT, and all NUMERIC values of scale <=18 and precision 0 are interchangeable. For NUMERIC data types, you cannot alter precision, but you can change the scale in the ranges (0-18), (19-37), and so on.

Vertica does not allow data type conversion on types that require storage reorganization:

Boolean type conversion to other types
DATE/TIME type conversion
Approximate numeric type conversions
Between BINARY and VARBINARY types

You can expand (and shrink) columns within the same class of data type, which is useful if you want to store longer strings in a column. Vertica validates the data before it performs the conversion.

For example, if you try to convert a column from varchar(25) to varchar(10) and that column holds a string with 20 characters, the conversion will fail. Vertica allow the conversion as long as that column does not have a string larger than 10 characters.

Post Reply

Return to “New to Vertica SQL”