<@U0A71G31CDV> This <page> suggests I can modify t...
# questions-and-troubleshooting
j
@Rocky This page suggests I can modify the default value on an existing column of an existing table. When I try this on StarRocks I get "mysql error: Can not change default value".
r
While the StarRocks documentation for
ALTER TABLE
includes
[ DEFAULT "<default_value>"]
in the syntax for
MODIFY COLUMN
, there is a significant limitation: StarRocks does not currently support changing the default value of an existing column. The error message
Can not change default value
occurs because the "Schema Change" process in StarRocks (which handles column modifications) is designed to handle data type conversions and reordering, but it does not support updating the metadata for the
DEFAULT
attribute of a column once it has been created. Key Points: * Documentation vs. Reality: The documentation suggests you can specify a
DEFAULT
value during a
MODIFY COLUMN
operation. However, this is typically required only to restate the existing default value if you are changing the column's data type. If you attempt to change the value itself, the system returns the error you encountered. * Version Limitation: This is a known behavior across most current versions (including 2.x and 3.x). While "Fast Schema Evolution" (introduced in v3.1+) has made adding and dropping columns faster, it has not yet enabled the modification of default values for existing columns. * Primary Key Tables: This limitation is particularly strict for Key columns and columns in Primary Key tables. Recommended Workarounds: If you need to change the default value for a column, you generally have two options: 1. Add a New Column (Recommended): * Add a new column with the desired default value:
Copy code
sql
        ALTER TABLE your_table ADD COLUMN new_col_name column_type DEFAULT "new_default_value";
* If necessary, update the new column with data from the old column:
Copy code
sql
        UPDATE your_table SET new_col_name = old_col_name;
* Drop the old column and rename the new one (Note: Column renaming is supported from v3.3.2 onwards):
Copy code
sql
        ALTER TABLE your_table DROP COLUMN old_col_name;
        ALTER TABLE your_table RENAME COLUMN new_col_name old_col_name;
2. Recreate the Table: For smaller tables or during development, the simplest path is to export the data, drop the table, and recreate it with the correct column definition. For more details on schema change limitations, you can refer to the StarRocks ALTER TABLE documentation. Referencesadministration/management/FE_configuration.mdsql-reference/sql-statements/table_bucket_part_index/CREATE_TABLE.mdsql-reference/sql-statements/table_bucket_part_index/ALTER_TABLE.md