数据仓库服务 GAUSSDB(DWS)-MERGE INTO:示例

时间:2024-11-28 20:10:36

示例

创建进行MERGE INTO的目标:
1
2
CREATE TABLE target(a int, b int)WITH(ORIENTATION = COLUMN, ENABLE_HSTORE = ON);
INSERT INTO target VALUES(1, 1),(2, 2);
创建数据源表:
1
2
CREATE TABLE source(a int, b int)WITH(ORIENTATION = COLUMN, ENABLE_HSTORE = ON);
INSERT INTO source VALUES(1, 1),(2, 2),(3, 3),(4, 4),(5, 5);
执行MERGE INTO操作:
1
2
3
4
5
6
7
MERGE INTO target t   
USING source s   
ON (t.a = s.a)   
WHEN MATCHED THEN  
  UPDATE SET t.b = t.b + 1  
WHEN NOT MATCHED THEN  
  INSERT VALUES (s.a, s.b) WHERE s.b % 2 = 0;
support.huaweicloud.com/HyDevg-830-dws/dws_15_00010.html