Note
Supported kernels: Presto, SparkSQL.
Applicable table scope: Native Iceberg tables, external tables.
Purpose: Supports inserting the results of SELECT queries run on the source table as new rows into the target table.
Syntax
[ WITH with_query [ , ... ] ]INSERT {INTO [<TABLE>]| TABLE} table_identifier [ partition_spec ] [ ( column_list ) ]{ VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ] | query }
Category
table_identifier: Specifies the table name, supports three-part notation, for example: catalog.database.table.partition_spec: Partition column and value. For example, dt='2021-06-01'.column_list: All of the columns.Query: A generic Select query statement. 1.1
a SELECT statement1.2
a TABLE statementSample
INSERT INTO orders SELECT * FROM new_orders;INSERT INTO cities VALUES (1, 'China');INSERT INTO nation (nationkey, name, regionkey, comment)VALUES (26, 'POLAND', 3, 'no comment');-- INSERT INTO partitionINSERT INTO students PARTITION (student_id = 444444) SELECT name, address FROM persons WHERE name = 'dlc'INSERT INTO students PARTITION (student_id = 11215017) (address, name) VALUES ('Shen zhen, China', 'tester')-- Insert Using a TABLE StatementINSERT INTO students TABLE visiting_students;-- withWITHtmp1AS ((SELECT *FROMcatalog1.db1.tbl1)),tmp2AS ((SELECT *FROMtbl2))INSERT INTOcatalog1.db2.tbl1(SELECTcol1,col2FROMtmp1aINNER JOINtmp2bONa.col1=b.col2)INSERT INTOcatalog1.db2.tbl1WITHtmp1AS ((SELECT *FROMcatalog1.db1.tbl1)),tmp2AS ((SELECT *FROMtbl2))(SELECTcol1,col2FROMtmp1aINNER JOINtmp2bONa.col1=b.col2)