jonahgao commented on code in PR #14572: URL: https://github.com/apache/datafusion/pull/14572#discussion_r1952677078
########## datafusion/common/src/dfschema.rs: ########## @@ -1028,21 +1028,41 @@ impl SchemaExt for Schema { }) } - fn logically_equivalent_names_and_types(&self, other: &Self) -> bool { + fn logically_equivalent_names_and_types(&self, other: &Self) -> Result<()> { if self.fields().len() != other.fields().len() { - return false; + _plan_err!( + "Inserting query must have the same schema length as the table. \ + Expected table schema length: {}, got: {}", + self.fields().len(), + other.fields().len() + ) + } else { + self.fields() + .iter() + .zip(other.fields().iter()) + .try_for_each(|(f1, f2)| { + // only check the case when the table field is not nullable and the insert data field is nullable + if !f1.is_nullable() && f2.is_nullable() { Review Comment: This condition would prevent the following query from executing, but it works on both the main branch and Postgres. ```sql create table t1(a int not null); create table t2(a int); insert into t2 values(100); insert into t1 select * from t2; ``` As I mentioned earlier, we already have a check during execution called [check_not_null_constraints](https://github.com/apache/datafusion/blob/2c73fcd47ed7391c7fd34d6c593c6f0c455670d0/datafusion/physical-plan/src/execution_plan.rs#L1003), so I think we should not add this restriction here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org