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

Julian Hyde commented on CALCITE-4771:
--------------------------------------

Returning {{NULL}} if the {{CAST}} fails is not compliant with the SQL 
standard, as I understand it. So, the type of a {{CAST}} should be nullable if 
and only if the type of the argument is nullable.

{{TRY_CAST}} is a good idea. Can you please review other major databases to see 
if they have similar operators, and report back here. If there is any consensus 
on the name, syntax and behavior of the operator, I would like to follow the 
consensus.

> change the value of the CAST function to be nullable 
> -----------------------------------------------------
>
>                 Key: CALCITE-4771
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4771
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: xuyangzhong
>            Priority: Major
>
> In the sql "SELECT CAST('haha' AS INT)",the value the function CAST returns 
> will be parsed  into NOT NULL, because when parsing, the type CAST returns is 
> from the INT and the nullable attribute is from the 'haha', which doesn't 
> consider the condition that parsing a string to an int could be invalid and 
> return NULL values.
> I think there are two ways to improve this question:
>  * One is to change the value of the CAST function to be nullable, which 
> avoids the invalid parsing.
>  * The other way is to introduce a function named TRY_CAST, which is used in 
> SQL Server.If the parsing fails, TRY_CAST will return NULL instead of throws 
> exception that a NOT NULL field will be set with our unexpected value NULL.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to