【问题标题】:How should i drop multiple columns in redshift database?我应该如何在 redshift 数据库中删除多个列?
【发布时间】:2018-06-28 17:07:55
【问题描述】:

您好,我正在尝试从我的表中删除列,特别是在 Amazon Redshift 数据库中我已经尝试过“Alter Table ABC drop column C1,drop column C2”和“ Alter Table ABC drop column C1,C2)" 但它显示错误并且没有执行

【问题讨论】:

  • ...发布跟踪代码和错误...并根据this修改问题。
  • FWIW,我来到这里是因为我在尝试使用 PostgreSQL 样式的语法删除多列后遇到了同样的问题,我得到了语法错误:ERROR: syntax error at or near "," 后跟指向 @ 的插入符号987654323@关注drop column C1,

标签: database amazon-redshift ddl


【解决方案1】:

来自Redshift's ALTER TABLE documentation,您不能同时删除几列,参见:

ALTER TABLE table_name
{
ADD table_constraint |
DROP CONSTRAINT constraint_name [ RESTRICT | CASCADE ] |
OWNER TO new_owner |
RENAME TO new_name |
RENAME COLUMN column_name TO new_name |
ADD [ COLUMN ] column_name column_type
[ DEFAULT default_expr ]
[ ENCODE encoding ]
[ NOT NULL | NULL ] |
DROP [ COLUMN ] column_name [ RESTRICT | CASCADE ] }

where table_constraint is:

[ CONSTRAINT constraint_name ]
{ UNIQUE ( column_name [, ... ] )  |
PRIMARY KEY ( column_name [, ... ] ) |
FOREIGN KEY (column_name [, ... ] )
REFERENCES  reftable [ ( refcolumn ) ]}

因此,我建议您按照以下方式进行:

ALTER TABLE ABC DROP COLUMN C1;
ALTER TABLE ABC DROP COLUMN C2;

【讨论】:

  • 这是正确的,ADD COLUMN 也是如此
猜你喜欢
  • 2018-11-12
  • 1970-01-01
  • 2011-07-04
  • 1970-01-01
  • 1970-01-01
  • 2011-08-12
  • 1970-01-01
  • 2018-02-04
  • 1970-01-01
相关资源
最近更新 更多