Updated on 2026-11-06 GMT+08:00

Writing Data to a Paimon Table

INSERT INTO

INSERT INTO my_table VALUES (1, 'Alice', '2024-01-01'); 
INSERT INTO my_table SELECT * FROM source_table; 

INSERT OVERWRITE

-- Overwrite the entire table.
INSERT OVERWRITE my_table SELECT ...;  
-- Overwrite specified partitions.
INSERT OVERWRITE my_table PARTITION (key1 = value1, key2 = value2) SELECT ...; 

Dynamic partition overwrite

Spark uses static overwrite mode by default. To enable dynamic overwrite, set the following parameters:

SET spark.sql.sources.partitionOverwriteMode=dynamic; 
INSERT OVERWRITE my_table VALUES (3, 'p1'); 

TRUNCATE TABLE

TRUNCATE TABLE my_table; 

UPDATE (only for primary key tables)

UPDATE my_table SET name = 'Alice Updated' WHERE id = 1;  
-- Update a field within a struct.
UPDATE t SET s.c2 = 'a_new' WHERE s.c1 = 1; 

Note: Primary Key tables do not support updating the values of primary key columns.

DELETE (only for primary key tables)

DELETE FROM my_table WHERE currency = 'UNKNOWN'; 

MERGE INTO (only for primary key tables)

MERGE INTO target
USING source
ON target.a = source.a
WHEN MATCHED THEN
    UPDATE SET *
WHEN NOT MATCHED THEN
    INSERT *;

Conditional MERGE INTO

MERGE INTO target
USING source
ON target.a = source.a
WHEN MATCHED AND target.a = 5 THEN
    UPDATE SET b = source.b + target.b
WHEN MATCHED AND source.c > 'c2' THEN
    UPDATE SET *
WHEN MATCHED THEN
    DELETE
WHEN NOT MATCHED AND c > 'c9' THEN
    INSERT (a, b, c) VALUES (a, b * 1.1, c)
WHEN NOT MATCHED THEN
    INSERT *;

Note: In the UPDATE clause, primary key tables do not support updating the values of primary key columns.