Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-18677

Sql. Arithmetic operation between numeric type and varchar columns and literals

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 3.0
    • sql
    • Docs Required, Release Notes Required

    Description

      Current implementation allows the following queries (1,2,3,4 and 5 fails at runtime):

      # 1
      SELECT 1::TINYINT + 1::VARCHAR
      
      # 2 
      SELECT 1::TINYINT + '1'
      
      # 3
      SELECT c + '1' FROM (VALUES(1, '1')) t(c, d);
      
      # 4
      SELECT c + d FROM (VALUES(1, '1')) t(c, d);
      
      # 5 - fails at runtime
      SELECT 1::TINYINT + 'b'
      
      Caused by: java.lang.NumberFormatException: For input string: "b"
      	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
      	at java.base/java.lang.Integer.parseInt(Integer.java:652)
      	at java.base/java.lang.Byte.parseByte(Byte.java:152)
      	at java.base/java.lang.Byte.parseByte(Byte.java:178)
      	at SC.execute(Unknown Source)
      	at org.apache.ignite.internal.sql.engine.exec.exp.ExpressionFactoryImpl$ProjectImpl.apply(ExpressionFactoryImpl.java:652)
      	at org.apache.ignite.internal.sql.engine.exec.rel.ProjectNode.push(ProjectNode.java:69)
      	at org.apache.ignite.internal.sql.engine.exec.rel.ScanNode.push(ScanNode.java:111)
      	at org.apache.ignite.internal.sql.engine.exec.ExecutionContext.lambda$execute$0(ExecutionContext.java:299)
      

      PostgreSQL:
      Query 1 is rejected because there is no addition operation between tinyint and varchar (we explicitly casted '1' to varchar)
      Query 2 is accepted because the second operand is implicitly converted to number since the literal looks like a number
      Query 3 is also accepted see (2)
      Query 4 is rejected because is no addition operation between tinyint and varchar because no implicit casts are added to columns (they have known type)

      We should consider whether we would like the same behaviour as PostgreSQL since it looks more consistent.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mzhuravkov Maksim Zhuravkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: