简体   繁体   English

如何更改 Redshift 中的列数据类型?

[英]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.

相关问题 如何屏蔽 Redshift 中的列? - How to mask a column in Redshift? 我无法在 firestore 数据库集合中将列 Kind 更改为 Type - I can't change the column Kind to Type on the firestore database collection 使用 dbt 进行 redshift 列编码 - redshift column encoding with dbt 如何从自定义 REST API 将数据加载到 Redshift - How to load data into Redshift from a custom REST API 如何更改 AWS Amplify 中的环境 - How do I change environments in AWS Amplify 如何通过 Python Boto3 将数据加载到 Amazon Redshift? - How to Load Data into Amazon Redshift via Python Boto3? 如何在 Redshift 的结果中保留列别名中的大写和小写字母 - How to keep the upper case and lower case letters in a column alias in the results in Redshift Redshift:我尝试使用 Union,但它返回 3 列而不是 4 列。我该怎么办? - Redshift: I try to use Union but it returns 3 columns instead of 4. What can I do? Firebase | 谷歌表 | 应用脚本 | 如何将列中的数据而不是行中的数据从 Firebase 保存到 Google 表格? - Firebase | Google Sheet | App Script | How do I save the data in column instead of row from Firebase to Google Sheet? 如何在 BigQuery 中将时间戳列转换为 MM/DD/YYYY - How do I cast a timestamp column as a MM/DD/YYYY in BigQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM