Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4771

Add TRY_CAST (MSSQL compatibility)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.35.0
    • None

    Description

      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.

       

      Attachments

        Issue Links

          Activity

            People

              FrankZou Dan Zou
              xuyangzhong xuyang
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 10m
                  2h 10m