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

Cast date to timestamp results in "ERROR 42846: Cannot convert types 'DATE' to 'TIMESTAMP'."

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 10.1.2.1
    • 10.10.2.0, 10.11.1.1
    • SQL
    • --------- Derby Information --------
      JRE - JDBC: J2SE 1.4.2 - JDBC 3.0
      [D:\Programme\Derby\bin\lib\derby.jar] 10.1.2.1 - (330608)
      [D:\Programme\Derby\bin\lib\derbytools.jar] 10.1.2.1 - (330608)
    • Normal
    • Repro attached

    Description

      Cast date to timestamp results in "ERROR 42846: Cannot convert types 'DATE' to 'TIMESTAMP'.",
      e.g. in ij:
      select cast(cast ('2006-01-01' as date) as timestamp) from sys.sysschemas;
      or
      select cast (current_date as timestamp) from bradi_dat.lpaip01;

      The similar issue exists for time ("ERROR 42846: Cannot convert types 'TIME' to 'TIMESTAMP'.",

      Documentation clearly states that these conversions are allowed, see table 1 in a description of CAST function in the Derby Reference Manual and comment about "Conversion of date/time values" below that table (see below as well).

      Conversions of date/time values
      A date/time value can always be converted to and from a TIMESTAMP. If a DATE is
      converted to a TIMESTAMP, the TIME component of the resulting TIMESTAMP is always
      00:00:00. If a TIME data value is converted to a TIMESTAMP, the DATE component is
      set to the value of CURRENT_DATE at the time the CAST is executed. If a TIMESTAMP
      is converted to a DATE, the TIME component is silently truncated. If a TIMESTAMP is
      converted to a TIME, the DATE component is silently truncated.

      Attachments

        1. allow-casts.diff
          2 kB
          Knut Anders Hatlen
        2. allow-casts-with-tests.diff
          23 kB
          Knut Anders Hatlen
        3. w.sql
          0.2 kB
          Richard N. Hillegas

        Issue Links

          Activity

            People

              knutanders Knut Anders Hatlen
              al0 Oleksandr Alesinskyy
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: