MaxCompute SQL では、1 つの SQL 文で複数の結果テーブルやパーティションを挿入できます。

SQL 文の形式
FROM from_statement
INSERT OVERWRITE | INTO TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)]
select_statement1 [FROM from_statement]
[INSERT OVERWRITE | INTO TABLE tablename2 [PARTITION (partcol1=val3, partcol2=val4 ...)]
select_statement2 [FROM from_statement]]
  • 通常、1 つの SQL 文で、最大 256 の出力を書き込めます。 出力先が 256 を超える場合は、構文エラーが発生します。
  • MULTI INSERT 文では、
    • パーティションテーブルの場合、書き込み先パーティションを複数回指定することはできません。
    • 非パーティションテーブルの場合、そのテーブルを複数回指定することはできません。
  • パーティションテーブル内の別のパーティションに INSERT OVERWRITE 操作および INSERT INTO 操作を同時に指定することはできません。指定するとエラーが返されます。
非パーティションテーブルの場合、そのテーブルを複数回指定することはできません。
create table sale_detail_multi like sale_detail;
from sale_detail
insert overwrite table sale_detail_multi partition (sale_date='2010', region='china' ) 
select shop_name, customer_id, total_price where .....
insert overwrite table sale_detail_multi partition (sale_date='2011', region='china' )
select shop_name, customer_id, total_price where .....
-- Return result successfully. Insert the data of sale_detail into the 2010 sales records and 2011 sales records in China region.
from sale_detail
insert overwrite table sale_detail_multi partition (sale_date='2010', region='china' )
select shop_name, customer_id, total_price
insert overwrite table sale_detail_multi partition (sale_date='2010', region='china' )
select shop_name, customer_id, total_price;
-- An error is thrown. The same partition appears for multiple times.
from sale_detail
insert overwrite table sale_detail_multi partition (sale_date='2010', region='china' )
select shop_name, customer_id, total_price
insert into table sale_detail_multi partition (sale_date='2011', region='china' )
select shop_name, customer_id, total_price;
-- An error is thrown. Different partitions within a partition table cannot have both an ‘insert overwrite’ operation and an ‘insert into’ operation.