diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java index f95efcd3474c9f..b9a745dad20746 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/NativeInsertStmt.java @@ -853,11 +853,15 @@ private void analyzeRow(Analyzer analyzer, List targetColumns, List buildRules() { // should not contain these unmentioned columns, so we just skip them. continue; } else if (column.getDefaultValue() == null) { + // throw exception if explicitly use Default value null when not nullable + // insert into table t values(DEFAULT) + if (!column.isAllowNull()) { + throw new AnalysisException("Column has no default value," + + " column=" + column.getName()); + } // Otherwise, the unmentioned columns should be filled with default values // or null values columnToOutput.put(column.getName(), new Alias( diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ReadLockTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ReadLockTest.java index 264891804ff85a..5d47127ea99863 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ReadLockTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/util/ReadLockTest.java @@ -109,7 +109,8 @@ public void testScalarSubQuery() { @Test public void testInsertInto() { - String sql = "INSERT INTO supplier(s_suppkey) SELECT lo_orderkey FROM lineorder"; + String sql = "INSERT INTO supplier(s_suppkey, s_name, s_address, s_city, s_nation, s_region, s_phone) " + + "SELECT lo_orderkey, '', '', '', '', '', '' FROM lineorder"; StatementContext statementContext = MemoTestUtils.createStatementContext(connectContext, sql); boolean originalDML = connectContext.getSessionVariable().enableNereidsDML; connectContext.getSessionVariable().enableNereidsDML = true;