[Fix] Only datetime and datetimev2 types can use current_timestamp as column default value (#31395)

for this kind of sql:

create table test_default10(
  a int, 
  b varchar(100) default current_timestamp
)
distributed by hash(a)
properties('replication_num'="1");

add check:
 Types other than DATETIME and DATETIMEV2 cannot use current_timestamp as the default value
This commit is contained in:
feiniaofeiafei
2024-02-27 15:34:48 +08:00
committed by yiguolei
parent fb1e08ee8c
commit 6b4a756837
3 changed files with 59 additions and 1 deletions

View File

@ -542,6 +542,16 @@ public class ColumnDef {
default:
throw new AnalysisException("Unsupported type: " + type);
}
if (null != defaultValueExprDef && defaultValueExprDef.getExprName().equals("now")) {
switch (primitiveType) {
case DATETIME:
case DATETIMEV2:
break;
default:
throw new AnalysisException("Types other than DATETIME and DATETIMEV2 "
+ "cannot use current_timestamp as the default value");
}
}
}
public String toSql() {