HIVE:CREATE TABLE AS SELECT 命令无法指定目标表的列列表

1 hadoop hive

我怎样才能做到这一点?

  hive> desc temp;
  OK
  a                     int                                         
  b                     int                                         
  Time taken: 0.077 seconds, Fetched: 2 row(s)
Run Code Online (Sandbox Code Playgroud)

我想创建列名为 c 和 d 的 t2 HIVE 表,但出现以下错误。

  hive> create table t2(c int,d int) as select a,b from temp;
  FAILED: SemanticException [Error 10065]: CREATE TABLE AS SELECT command         cannot specify the list of columns for the target table
Run Code Online (Sandbox Code Playgroud)

Kir*_*uri 5

您无需再次提及表架构,因为您指定从另一个表获取架构。所以你的表创建语句应该是这样的

create table t2 as select a,b from temp;
Run Code Online (Sandbox Code Playgroud)

  • 你不能那样做。创建表后,您可以使用 alter 语句更改列名称。ALTER TABLE 表名 CHANGE [COLUMN] col_old_name col_new_name 列类型 [COMMENT col_comment] [FIRST|AFTER column_name] (2认同)