简体   繁体   中英

How do I change column data type in Redshift?

I have tried changing the column data type in Redshift via SQL. Keep getting an error:

[Amazon][Amazon Redshift] (30) Error occurred while trying to execute a query: [SQLState 42601] ERROR: syntax error at or near "TABLE" LINE 17: ALTER TABLE bmd_disruption_fv ^ Unable to connect to the Amazon Redshift server 'eceim.master.datamart.eceim.sin.auto.prod.c0.sq.com.sg'. Check that the server is running and that you have access privileges to the requested database

The first sql query works. I have tried writing the Alter Table script before the Select lines but it did not work too.

`

*Extract selected columns and renaming them for easier reference
*/

select ID, Completion_Time AS Date_Reported, Name2 AS Name, Contact_Info_for_updates AS Contact_Info,
Your_operation_line AS Operation_Line, Aircraft_Registration_SMU_SMT_etc AS Aircraft_Reg, 
Designation_trade_B1_B2_ACT_AST_AAT AS Trade, Choose_your_Issue AS Issue, Manpower, Material, Equipment_GES,
Information, Tools, State_details_here_SVO_number_too AS Issue_Details, Time_wasted_on_due_to_issue AS Time_Wasted,
State_additional_comments_suggestions AS Additional_Comments, Stakeholders, Status

from bmdm.bmd_disruption_fv

/*Change colum data type
*/

ALTER TABLE bmd_disruption_fv
{
ALTER COLUMN ID TYPE INT
}

`

Several things are causing issues here. First the curly brackets '{}' should not be in the alter table statement. Like this:

alter table event alter column eventname type varchar(300);

Second, and likely more importantly, you can only change the length of varchar columns. So changing a column type to INT is not possible. You will need to perform a multistep process to make this change to the table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM