Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-6569

NULLIF may return incorrect results if first operand calls non-deterministic function

    XMLWordPrintableJSON

Details

    • Repro attached
    • Deviation from standard

    Description

      The SQL standard doesn't allow non-deterministic function calls in the operands of NULLIF. Derby does however allow such calls, but the results may not be as one might expect.

      Take an expression such as NULLIF(expr, 1). It shouldn't ever return 1. If expr is 1, it should return NULL, and if expr is not 1, it should return expr.

      If expr contains a call to a non-deterministic function, it may actually end up returning 1 sometimes:

      ij> SELECT NULLIF(INT(RANDOM()*2), 1) FROM SYS.SYSTABLES;
      1          
      -----------
      1          
      1          
      1          
      NULL       
      NULL       
      NULL       
      NULL       
      0          
      1          
      NULL       
      NULL       
      0          
      0          
      NULL       
      0          
      1          
      0          
      NULL       
      1          
      0          
      NULL       
      NULL       
      NULL       
      
      23 rows selected
      

      Attachments

        1. d6569-1a.diff
          10 kB
          Knut Anders Hatlen
        2. d6569-1b.diff
          3 kB
          Knut Anders Hatlen

        Issue Links

          Activity

            People

              knutanders Knut Anders Hatlen
              knutanders Knut Anders Hatlen
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: