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

[DOC] CAST conversions between data types table is incorrect in Reference manual in some VARCHAR and TIMESTAMP cases

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 10.2.2.0
    • 10.2.1.6, 10.3.1.4
    • Documentation
    • None

    Description

      The CAST function documentation contains a table which lists the explicit conversions between data types.
      http://db.apache.org/derby/docs/10.2/ref/rrefsqlj33562.html

      For the 'SOURCE' values (the columns) of SMALLINT, INTEGER, BIGINT and DECIMAL the CAST to VARCHAR is listed. However, they should not be listed because this cast is not allowed. See the output below;

      ij> create table smallint_tab(id integer, col2 smallint);
      0 rows inserted/updated/deleted
      ij> insert into smallint_tab values (1, 10);
      1 row inserted/updated/deleted
      ij> select cast(col2 as varchar(10)) from smallint_tab;
      ERROR 42846: Cannot convert types 'SMALLINT' to 'VARCHAR'.

      Also from integer to varchar does not work:

      ij> create table int_tab (id integer, col2 integer);
      0 rows inserted/updated/deleted
      ij> insert into int_tab values (1, 10);
      1 row inserted/updated/deleted
      ij> select cast(col2 as varchar(20)) from int_tab;
      ERROR 42846: Cannot convert types 'INTEGER' to 'VARCHAR'.

      Bigint neither:

      ij> create table bigint_tab (id integer, col2 bigint);
      0 rows inserted/updated/deleted
      ij> insert into bigint_tab values (1, 10);
      ij> select cast(col2 as varchar(20)) from bigint_tab;
      ERROR 42846: Cannot convert types 'BIGINT' to 'VARCHAR'.

      Nor decimal:

      ij> create table decimal_tab (id integer, col2 decimal);
      0 rows inserted/updated/deleted
      ij> insert into decimal_tab values (1, 1.88);
      1 row inserted/updated/deleted
      ij> select cast(col2 as varchar(3)) from decimal_tab;
      ERROR 42846: Cannot convert types 'DECIMAL' to 'VARCHAR'.

      The Cast from DATE to TIMESTAMP and TIME to TIMESTAMP also are not allowed, although they
      are listed. They need to be removed;

      ij> create table date_tab (id integer, col2 date);
      0 rows inserted/updated/deleted
      ij> insert into date_tab values (1, CURRENT_DATE);
      1 row inserted/updated/deleted
      ij> select cast(col2 as timestamp) from date_tab;
      ERROR 42846: Cannot convert types 'DATE' to 'TIMESTAMP'.

      ij> create table time_tab (id integer, col2 time);
      0 rows inserted/updated/deleted
      ij> insert into time_tab values (1, CURRENT_TIME);
      1 row inserted/updated/deleted
      ij> select cast(col2 as timestamp) from time_tab;
      ERROR 42846: Cannot convert types 'TIME' to 'TIMESTAMP'.

      Attachments

        1. derby1804.diff
          3 kB
          Laura Stewart
        2. rrefsqlj33562.html
          33 kB
          Laura Stewart

        Activity

          People

            scotsmatrix Laura Stewart
            slc Susan Cline
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: