[英]How do I change column data type in Redshift?
I have tried changing the column data type in Redshift via SQL.我尝试通过 SQL 更改 Redshift 中的列数据类型。 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'. [Amazon][Amazon Redshift] (30) 尝试执行查询时发生错误:[SQLState 42601] 错误:“TABLE”第 17 行或附近的语法错误:ALTER TABLE bmd_disruption_fv ^ 无法连接到 Amazon Redshift 服务器 '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.第一个 sql 查询有效。 I have tried writing the Alter Table script before the Select lines but it did not work too.
我曾尝试在 Select 行之前编写 Alter Table 脚本,但它也没有用。
` `
*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.
首先,大括号“{}”不应出现在 alter table 语句中。 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.其次,可能更重要的是,您只能更改 varchar 列的长度。 So changing a column type to INT is not possible.
所以将列类型更改为 INT 是不可能的。 You will need to perform a multistep process to make this change to the table.
您将需要执行一个多步骤过程来对表进行此更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.