Derby
  1. Derby
  2. DERBY-5130

Allow for LONG VARCHAR to be compared to LONG VARCHAR

    Details

    • Urgency:
      Normal
    • Issue & fix info:
      Workaround attached

      Description

      Interestingly, this is not possible:

      select 1 from SYSIBM.SYSDUMMY1 where cast('2' as long varchar) = cast('2' as long varchar)

      Whereas these statements are executable:

      select 1 from SYSIBM.SYSDUMMY1 where '2' = '2'
      select 1 from SYSIBM.SYSDUMMY1 where cast(cast('2' as long varchar) as varchar(1)) = cast(cast('2' as long varchar) as varchar(1))

      According to the documentation that is the correct behaviour:
      http://db.apache.org/derby/docs/10.7/ref/rrefsqlj58560.html

      Nevertheless, if casting is possible between LONG VARCHAR and VARCHAR, and assignment too, then I don't understand why LONG VARCHAR cannot even be compared to LONG VARCHAR

      Note: A similar issue has been open for a long time:
      https://issues.apache.org/jira/browse/DERBY-342

        Issue Links

          Activity

          Lukas Eder created issue -
          Lukas Eder made changes -
          Field Original Value New Value
          Link This issue is related to DERBY-342 [ DERBY-342 ]
          Hide
          Lukas Eder added a comment -

          Similar but not entirely the same discussion

          Show
          Lukas Eder added a comment - Similar but not entirely the same discussion
          Hide
          Rick Hillegas added a comment -

          Hi Lukas,

          For the same reason, you can't build an index on a long varchar column or use it in any of the SQL ordering contexts (ORDER BY clauses, GROUP BY clauses, etc.). The workaround is to cast long varchar to varchar(32672):

          connect 'jdbc:derby:memory:db;create=true';

          create table t( a long varchar, b long varchar );

          – fails because the datatype is not orderable
          select * from t where a = b;

          – succeeds although you may get truncation errors at runtime
          select * from t where cast( a as varchar(32672) ) = cast( b as varchar(32672) );

          Show
          Rick Hillegas added a comment - Hi Lukas, For the same reason, you can't build an index on a long varchar column or use it in any of the SQL ordering contexts (ORDER BY clauses, GROUP BY clauses, etc.). The workaround is to cast long varchar to varchar(32672): connect 'jdbc:derby:memory:db;create=true'; create table t( a long varchar, b long varchar ); – fails because the datatype is not orderable select * from t where a = b; – succeeds although you may get truncation errors at runtime select * from t where cast( a as varchar(32672) ) = cast( b as varchar(32672) );
          Rick Hillegas made changes -
          Labels comparison sql typesystem comparison derby_triage10_8 sql typesystem
          Issue & fix info [Workaround attached]
          Hide
          Lukas Eder added a comment -

          Hmm, you're right. I agree that it is consistent with the idea of ordering contexts... I guess you can reject this issue.

          Show
          Lukas Eder added a comment - Hmm, you're right. I agree that it is consistent with the idea of ordering contexts... I guess you can reject this issue.
          Gavin made changes -
          Workflow jira [ 12607522 ] Default workflow, editable Closed status [ 12800949 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Lukas Eder
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:

                Development