更新时间:2022-09-30 GMT+08:00

UPDATE CARBON TABLE

命令功能

UPDATE命令根据列表达式和可选的过滤条件更新CarbonData表。

命令格式

  • 格式1:

    UPDATE <CARBON TABLE> SET (column_name1, column_name2, ... column_name n) = (column1_expression , column2_expression , column3_expression ... column n_expression ) [ WHERE { <filter_condition> } ];

  • 格式2:

    UPDATE <CARBON TABLE> SET (column_name1, column_name2,) = (select sourceColumn1, sourceColumn2 from sourceTable [ WHERE { <filter_condition> } ] ) [ WHERE { <filter_condition> } ];

参数描述

表1 UPDATE参数

参数

描述

CARBON TABLE

在其中执行更新操作的CarbonData表的名称。

column_name

待更新的目标列。

sourceColumn

需在目标表中更新的源表的列值。

sourceTable

将其记录更新到目标CarbonData表中的表。

注意事项

以下是使用UPDATE命令的条件:

  • 如果源表中的多个输入行与目标表中的单行匹配,则UPDATE命令失败。
  • 如果源表生成空记录,则UPDATE操作将在不更新表的情况下完成。
  • 如果源表的行与目标表中任何已有的行不对应,则UPDATE操作将完成,不更新表。
  • 具有二级索引的表不支持UPDATE命令。
  • 在子查询中,如果源表和目标表相同,则UPDATE操作失败。
  • 如果在UPDATE命令中使用的子查询包含聚合函数或group by子句,则UPDATE操作失败。

    例如,update t_carbn01 a set (a.item_type_code, a.profit) = ( select b.item_type_cd, sum(b.profit) from t_carbn01b b where item_type_cd =2 group by item_type_code);

    其中,在子查询中使用聚合函数sum(b.profit)和group by子句,因此UPDATE操作失败。

  • 如果查询的表设置了carbon.input.segments属性,则UPDATE操作失败。要解决该问题,在查询前执行以下语句。

    语法:

    SET carbon.input.segments. <database_name>. <table_name>=*;

示例

  • 示例1:

    update carbonTable1 d set (d.column3,d.column5 ) = (select s.c33 ,s.c55 from sourceTable1 s where d.column1 = s.c11) where d.column1 = 'country' exists( select * from table3 o where o.c2 > 1);

  • 示例2:

    update carbonTable1 d set (c3) = (select s.c33 from sourceTable1 s where d.column1 = s.c11) where exists( select * from iud.other o where o.c2 > 1);

  • 示例3:

    update carbonTable1 set (c2, c5 ) = (c2 + 1, concat(c5 , "y" ));

  • 示例4:

    update carbonTable1 d set (c2, c5 ) = (c2 + 1, "xyx") where d.column1 = 'india';

  • 示例5:

    update carbonTable1 d set (c2, c5 ) = (c2 + 1, "xyx") where d.column1 = 'india' and exists( select * from table3 o where o.column2 > 1);

系统响应

可在driver日志和客户端中查看命令运行成功或失败。