ALTER COLUMN
Function
The ALTER TABLE ... ALTER COLUMN command is used to change the attributes of a column, such as the column type, position, and comment.
Syntax
ALTER TABLE Table name ALTER
[COLUMN] col_old_name TYPE column_type
[COMMENT] col_comment
[FIRST|AFTER] column_name
Parameter Description
Parameter |
Description |
---|---|
tableName |
Table name. |
col_old_name |
Name of the column to be altered. |
column_type |
Type of the target column. |
col_comment |
Column comment. |
column_name |
New position to place the target column. For example, AFTER column_name indicates that the target column is placed after column_name. |
Example
- Changing the column type
ALTER TABLE table1 ALTER COLUMN a.b.c TYPE bigint
a.b.c indicates the full path of a nested column. For details about the nested column rules, see ADD COLUMNS.
The following changes on column types are supported:
- int => long/float/double/string/decimal
- long => float/double/string/decimal
- float => double/String/decimal
- From double to string or decimal
- From decimal to decimal or string
- From string to date or decimal
- From date to string
- Altering other attributes
ALTER TABLE table1 ALTER COLUMN a.b.c DROP NOT NULL ALTER TABLE table1 ALTER COLUMN a.b.c COMMENT 'new comment' ALTER TABLE table1 ALTER COLUMN a.b.c FIRST ALTER TABLE table1 ALTER COLUMN a.b.c AFTER x
a.b.c indicates the full path of a nested column. For details about the nested column rules, see ADD COLUMNS.
Response
You can run the DESCRIBE command to view the modified column.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot