Derby
  1. Derby
  2. DERBY-2147

LIKE predicate does not accept a pure column reference as righthand operand (gives ERROR 42824)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 10.3.1.4
    • Fix Version/s: 10.3.1.4
    • Component/s: SQL
    • Labels:
      None

      Description

      Given "create table t (v varchar(32));" the query "select * from t where 'dilldall' like v; " gives ERROR 42824.
      The problem is easily bypassed using a cast: "select * from t where 'dilldall' like cast (v as varchar(32));".

      create table t (v varchar(32));
      insert into t values ('%lda%');
      select * from t where 'dilldall' like v; – ERROR 42824: An operand of LIKE is not a string, or the first operand is not a column.
      select * from t where 'dilldall' like cast (v as varchar(32)); – 1 row. OK
      select * from t where v like 'dilldall'; – 0 rows - OK, not a pattern as right op.
      select * from t where cast (v as varchar(32)) like 'dilldall'; – 0 rows - OK, not a pattern as right op.

      A column reference as a righthand operand should be accepted according to
      ISO/IEC 9075-2:1999 (E):

      8.5 <like predicate>
      <like predicate> ::=
      <character like predicate> | <octet like predicate>
      <character like predicate> ::=
      <character match value> [ NOT ] LIKE <character pattern> [ ESCAPE <escape character> ]
      <character match value> ::= <character value expression>
      <character pattern> ::= <character value expression>

      6.27 <string value expression>
      <character value expression> ::= <concatenation> | <character factor>
      <character factor> ::= <character primary> [ <collate clause> ]
      <character primary> ::= <value expression primary> | <string value function>

      6.23 <value expression>
      <value expression primary> ::= <parenthesized value expression> | <nonparenthesized value expression primary>
      <nonparenthesized value expression primary> ::= <unsigned value specification> | <column reference> | ....

      1. DERBY-2147.stat
        0.4 kB
        Bernt M. Johnsen
      2. DERBY-2147.diff
        9 kB
        Bernt M. Johnsen

        Issue Links

          Activity

          Hide
          Bernt M. Johnsen added a comment -

          Seems to be a simple DB2 compliancy that may be removed from LikeEscapeOperatorNode.bindExpression:
          // pattern cannot be a column
          if (leftOperand instanceof ColumnReference)
          throw StandardException.newException(SQLState.LANG_DB2_LIKE_SYNTAX_ERROR);

          Show
          Bernt M. Johnsen added a comment - Seems to be a simple DB2 compliancy that may be removed from LikeEscapeOperatorNode.bindExpression: // pattern cannot be a column if (leftOperand instanceof ColumnReference) throw StandardException.newException(SQLState.LANG_DB2_LIKE_SYNTAX_ERROR);
          Hide
          Bernt M. Johnsen added a comment -

          The same applies to the escape character which is caught by:
          // escape cannot be a column
          if (rightOperand != null && rightOperand instanceof ColumnReference)

          { throw StandardException.newException(SQLState.LANG_INVALID_ESCAPE_CHARACTER, ((ColumnReference) rightOperand).getColumnName()); }
          Show
          Bernt M. Johnsen added a comment - The same applies to the escape character which is caught by: // escape cannot be a column if (rightOperand != null && rightOperand instanceof ColumnReference) { throw StandardException.newException(SQLState.LANG_INVALID_ESCAPE_CHARACTER, ((ColumnReference) rightOperand).getColumnName()); }
          Hide
          Bernt M. Johnsen added a comment -

          Removed the two tests that disables this functionality.
          Updated master for lang/dynamicLikeOptimization.sql
          Commented out the corresponding tests in lang/db2Compatability.sql and updated master

          Show
          Bernt M. Johnsen added a comment - Removed the two tests that disables this functionality. Updated master for lang/dynamicLikeOptimization.sql Commented out the corresponding tests in lang/db2Compatability.sql and updated master
          Hide
          Bernt M. Johnsen added a comment -

          Committed revision 488672.

          Show
          Bernt M. Johnsen added a comment - Committed revision 488672.

            People

            • Assignee:
              Bernt M. Johnsen
              Reporter:
              Ole Solberg
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development