Uploaded image for project: 'Apache Trafodion'
  1. Apache Trafodion
  2. TRAFODION-3071

DATEDIFF function gives strange results when executed on interval data types

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.3
    • Component/s: sql-cmp
    • Labels:
      None

      Description

      According to the SQL reference manual, http://trafodion.apache.org/docs/sql_reference/index.html#datediff_function, the DATEDIFF function is limited to DATE and TIMESTAMP operands.

      If one attempts DATEDIFF on INTERVAL data types, the errors are strange and non-intuitive. In some cases, DATEDIFF even succeeds on an INTERVAL data type. The following session output illustrates:

      >>drop table if exists t;

      — SQL operation complete.
      >>create table t (c1 interval year, c2 interval year to month, c3 interval month);

      — SQL operation complete.
      >>insert into t values (interval '11' year, interval '22-02' year to month, interval '33' month);

      — 1 row(s) inserted.
      >>
      >>select DATEDIFF(MONTH, c1, c1) from t;

          • ERROR[4037] Field MONTH cannot be extracted from a source of type INTERVAL YEAR(2).
          • ERROR[4062] The preceding error actually occurred in function DATEDIFF.
          • ERROR[8822] The statement was not prepared.

      >>select DATEDIFF(MONTH, c2, c2) from t;

      (EXPR)
      -----------

      0

      — 1 row(s) selected.
      >>select DATEDIFF(MONTH, c3, c3) from t;

          • ERROR[4037] Field YEAR cannot be extracted from a source of type INTERVAL MONTH(2).
          • ERROR[4062] The preceding error actually occurred in function DATEDIFF.
          • ERROR[8822] The statement was not prepared.

      >>

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dbirdsall Dave Birdsall
                Reporter:
                dbirdsall Dave Birdsall
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: