Hi everyone,

I want to start a discussion about default values in Paimon.

Paimon can allow 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

User 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 values.

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;.

What do you think?

Best,
Jingsong

Reply via email to