This documentation is for an unreleased version of Apache Paimon. We recommend you use the latest stable version.
Default Value
Default Value #
Paimon allows specifying default values for columns. When users write to these tables without explicitly providing values for certain columns, Paimon automatically generates default values for these columns.
Create Table #
You can create a table with columns with default values using the following SQL:
CREATE TABLE my_table (
a BIGINT,
b STRING DEFAULT 'my_value',
c INT DEFAULT 5
);
Insert Table #
For SQL commands that execute table writes, such as the INSERT
, UPDATE
, and MERGE
commands, the DEFAULT
keyword
or NULL
value is parsed into the default value specified for the corresponding column.
Alter Default Value #
Paimon supports alter column default value.
For example:
CREATE TABLE T (a INT, b INT DEFAULT 2);
INSERT INTO T (a) VALUES (1);
-- result: [[1, 2]]
ALTER TABLE T ALTER COLUMN b SET DEFAULT 3;
INSERT INTO T (a) VALUES (2);
-- result: [[1, 2], [2, 3]]
The default value of 'b'
column has been changed to 3 from 2.
Limitation #
Not support alter table add column with default value, for example: ALTER TABLE T ADD COLUMN d INT DEFAULT 5;
.