Hi Jingsong,

Thank you for initiating this discussion about default values in Paimon.

The ability to specify default values for columns during table creation
offers a streamlined approach to handling situations where certain data may
not be provided by users. This feature reduces the risk of errors and
maintains data consistency without additional overhead.
Supporting the alteration of default values (as shown with the ALTER TABLE
T ALTER COLUMN b SET DEFAULT 3 example) increases the adaptability of
schema management. This feature ensures that evolving data requirements can
be accommodated without the need for complex migrations or modifications to
existing data.

I hava a question:
1. For columns which has default value, could the user alter its type?
2. Will there be a procedure to help users update the default values for
historical data?

Jingsong Li <jingsongl...@gmail.com> 于2025年6月16日周一 23:08写道:

> 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