File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed
src/query/sql/src/planner/binder/ddl
tests/sqllogictests/suites/base/05_ddl Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -528,7 +528,7 @@ impl Binder {
528528 . map ( |column_binding| {
529529 Ok ( TableField :: new (
530530 & column_binding. column_name ,
531- infer_schema_type ( & column_binding. data_type ) ?,
531+ create_as_select_infer_schema_type ( & column_binding. data_type ) ?,
532532 ) )
533533 } )
534534 . collect :: < Result < Vec < _ > > > ( ) ?;
@@ -1766,3 +1766,12 @@ async fn verify_external_location_privileges(dal: Operator) -> Result<()> {
17661766 . await
17671767 . expect ( "join must succeed" )
17681768}
1769+
1770+ fn create_as_select_infer_schema_type ( data_type : & DataType ) -> Result < TableDataType > {
1771+ match data_type {
1772+ DataType :: Null => Ok ( TableDataType :: Nullable ( Box :: new ( TableDataType :: String ) ) ) ,
1773+ _ => {
1774+ infer_schema_type ( data_type)
1775+ }
1776+ }
1777+ }
Original file line number Diff line number Diff line change @@ -288,9 +288,6 @@ create table t(a int, A int)
288288statement error Duplicated column name
289289create table t as select number, number from numbers(1)
290290
291- statement error 1006
292- create table t as select 'a' as c1, null as c2;
293-
294291statement error 4000
295292create table tb101 (id int ,c1 datetime) 's3://wubx/tb101' connection=(aws_key_id='minioadmin' aws_ssecret_key='minioadmin' endpoint_url='http://127.0.0.1:9900');
296293
@@ -598,3 +595,25 @@ statement ok
598595alter table t_opt_retention set options(data_retention_period_in_hours = 2);
599596
600597
598+ #issue 16794
599+ statement ok
600+ create or replace table b as select 123 as col1, null as col2;
601+
602+ query T
603+ desc b;
604+ ----
605+ col1 TINYINT UNSIGNED NO 0 (empty)
606+ col2 VARCHAR YES NULL (empty)
607+
608+ query T
609+ show create table b;
610+ ----
611+ b CREATE TABLE b ( col1 TINYINT UNSIGNED NOT NULL, col2 VARCHAR NULL ) ENGINE=FUSE
612+
613+ query TT
614+ select * from b;
615+ ----
616+ 123 NULL
617+
618+ statement ok
619+ drop table if exists b;
You can’t perform that action at this time.
0 commit comments