IBM Support

LI72810: EARLY EVALUATION OF EXPRESSION IN SQL UDF RESULTS IN RUNTIME ERROR.

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • An expression within a SQL UDF that should not be executed due
    to the procedural logic (e.g. within an IF statement) is
    executed anyway and may result in a runtime error.
    
    To illustrate the problem, consider the following UDF:
    
    --------------------
    CREATE FUNCTION GETDATE( iYear VARCHAR(4), iMonth VARCHAR(2) )
        RETURNS DATE
        LANGUAGE SQL
    BEGIN atomic
        IF iYear BETWEEN '0000' AND '9999' AND
           iMonth BETWEEN '01' AND '12'
        THEN
          RETURN DATE( iYear || iMonth || '01' ); --
        END IF; --
    
        RETURN NULL; --
    END;
    --------------------
    
    When executed with a month of '13', the expression "DATE( iYear
    || iMonth || '01' )" is evaluated despite the fact that the IF
    predicate is false and results in a runtime error:
    
    
    VALUES GETDATE( '2007', '13' );
    SQL0181N  The string representation of a datetime value is out
    of range.
    SQLSTATE=22007
    
    The expression is executed due to early evaluation optimization.
    

Local fix

  • Replace the input argument variables in the failing expression
    with local variables, for example:
    
    --------------------
    CREATE FUNCTION GETDATE( iYear VARCHAR(4), iMonth VARCHAR(2) )
        RETURNS DATE
        LANGUAGE SQL
    BEGIN atomic
        DECLARE year  VARCHAR(4); --
        DECLARE month VARCHAR(2); --
    
        IF iYear BETWEEN '0000' AND '9999' AND
           iMonth BETWEEN '01' AND '12'
        THEN
          set year = iYear; --
          set month = iMonth; --
          RETURN DATE( year || month || '01' ); --
        END IF; --
    
        RETURN NULL; --
    END;
    --------------------
    

Problem summary

  • Problem:
    EARLY EVALUATION OF EXPRESSION IN SQL UDF RESULTS IN RUNTIME
    ERROR.
    
    Users affected:
    All the users using V95 GA.
    Problem description:
    An expression within a SQL UDF that should not be executed due
    to the procedural logic (e.g. within an IF statement) is
    executed anyway and may result in a runtime error.
    
    To illustrate the problem, consider the following UDF:
    
    --------------------
    CREATE FUNCTION GETDATE( iYear VARCHAR(4), iMonth VARCHAR(2) )
        RETURNS DATE
        LANGUAGE SQL
    BEGIN atomic
        IF iYear BETWEEN '0000' AND '9999' AND
           iMonth BETWEEN '01' AND '12'
        THEN
          RETURN DATE( iYear || iMonth || '01' ); --
        END IF; --
    
        RETURN NULL; --
    END;
    --------------------
    
    When executed with a month of '13', the expression "DATE( iYear
    || iMonth || '01' )" is evaluated despite the fact that the IF
    predicate is false and results in a runtime error:
    
    
    VALUES GETDATE( '2007', '13' );
    SQL0181N  The string representation of a datetime value is out
    of range.
    SQLSTATE=22007
    
    The expression is executed due to early evaluation optimization.
    

Problem conclusion

  • First fixed in DB2 UDB Version 9.5, FixPak 1.
    

Temporary fix

Comments

APAR Information

  • APAR number

    LI72810

  • Reported component name

    DB2 UDE ESE LIN

  • Reported component ID

    5765F4104

  • Reported release

    950

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2007-12-03

  • Closed date

    2008-05-04

  • Last modified date

    2008-05-04

  • APAR is sysrouted FROM one or more of the following:

    LI72808

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    DB2 UDE ESE LIN

  • Fixed component ID

    5765F4104

Applicable component levels

  • R810 PSY

       UP

  • R820 PSY

       UP

  • R910 PSY

       UP

  • R950 PSY

       UP

[{"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSEPGG","label":"DB2 for Linux, UNIX and Windows"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"950","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
04 May 2008