You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Shengkai Fang (Jira)" <ji...@apache.org> on 2022/05/27 04:31:00 UTC

[jira] [Commented] (FLINK-27795) SqlValidatorException when insert null value

    [ https://issues.apache.org/jira/browse/FLINK-27795?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17542774#comment-17542774 ] 

Shengkai Fang commented on FLINK-27795:
---------------------------------------

Hi. I think it's by design. In the SQL world, we can insert value into the table only if the type is same. So we need to derive the type from the value in your SQL. Here the type of the value NULL is NullType that is not equal to the type in the sink(Varchar type). Therefore, you should cast explictly. 

> SqlValidatorException when insert null value
> --------------------------------------------
>
>                 Key: FLINK-27795
>                 URL: https://issues.apache.org/jira/browse/FLINK-27795
>             Project: Flink
>          Issue Type: Bug
>          Components: Table SQL / API
>    Affects Versions: 1.14.4
>            Reporter: linqichen
>            Priority: Major
>
> Hello , I found a problem, when i try to insert null value. 
> i think it is very common to insert null to string type value. We should solve this instead of using  cast (xx as string)
> -----------------------------------------------------------------
> Flink SQL> create table print_1(
> >   name string
> > ) with(
> > 'connector'='print'
> > );
> [INFO] Execute statement succeed.
> Flink SQL> insert into print_1 (name) values (null);
> {color:#de350b}*[ERROR] Could not execute SQL statement. Reason:*{color}
> {color:#de350b}*org.apache.calcite.sql.validate.SqlValidatorException: Illegal use of 'NULL'*{color}
>  



--
This message was sent by Atlassian Jira
(v8.20.7#820007)