Comparison Operators¶
Comparison operators are used in conditions to compare one expression with another. The result of the comparison can be true or false or unknown.
Important
Any comparison with a null value returns unknown. If a query has a WHERE and/or HAVING clause, only the rows for which the condition returns true are added to the result.
This behavior is defined by the SQL standard. The section Three-valued Logic explains this in more detail.
The comparison operators are the following:
a < b: true ifais less thanb.a <= b: true ifais less than or equal tob.a > b: true ifais greater thanb.a >= b: true ifais greater than or equal tob.a = b: true ifaandbare equal.a <> b: true ifais different thanb.a LIKE b: true ifamatches the patternb.bis an expression of type text and can include these wildcard characters:%(percentage): represents a segment of text of any length, including an empty text._(underscore): represents any character (only one character).
Optionally, you can indicate the
ESCAPEclause followed by any character. This character is called “escape character”. If the escape character is placed in front of a wildcard character (_or%), it indicates that the wildcard has to be interpreted as a regular character and not as a wildcard.The default value for the escape character is the
$(dollar).If the pattern includes the characters
%or_and you want to consider them as literals and not wildcards, escape them by prefixing them with the escape character. That is, the character indicated in theESCAPEparameter or if you do not indicate that, with dollar. For example, “$$”.Example 1) the pattern
'%commerce_'matches any string ending with the substring'commerce'followed by any character. For example, these values match this pattern: “commerce1”, “New commerce2”.Example 2) the following query returns the rows of the view
internet_incwhosesummarycontain the textadsl:SELECT * FROM internet_inc WHERE summary like '%adsl%'Example 3) to obtain all the rows whose value for the column
discountis “30%” use this condition:SELECT ... FROM ... WHERE discount LIKE '30~%' ESCAPE '~'The escape character ~ indicates that the percentage character after “30” does not have to be treated as a wildcard.
a regexp_like b: true ifamatches the patternb.bis a Java regular expression.If you want to do a case-insensitive comparison, use the operator
regexp_ilikebecause the performance will be better than if you use a regular expression that ignores the case (i.e. a regular expression that starts with?i).Examples: Consider the following view
PRODUCTS:IDENTIFIER
NAME
AJ00
Product A
AJ17
Product B
AJ1A8
Product C
PQ983
Product D
PQ00
Product E
The query
SELECT * FROM products WHERE identifier regexp_like 'AJ\d+'returns the rows:IDENTIFIER
NAME
AJ00
Product A
AJ17
Product B
a regexp_ilike b: true ifamatches the patternb, ignoring case differences.bis a Java regular expression .a is not NULL: true ifais not null.a is NULL: true ifais null.a is TRUE: true ifais a boolean expression and is true.a is FALSE: true ifais a boolean expression and is false.a in (b [, c]* ): true ifais equal to one or more expressions on the right-side (b,c…).Example: The following statement selects the tuples from the view
internet_incfor which their value for thetaxidattribute isB78596011orB78596012:SELECT * FROM internet_inc WHERE taxid in ('B78596011', 'B78596012')
To limit the maximum number of values allowed for IN operator, execute this command:
SET 'com.denodo.vdb.interpreter.parser.condition.maxValuesOnInOperator' = '<enter an integer greater than 0>';
a between b and c: true ifais greater than or equal toband less than or equal toc.Example: The following two statements produce the same result: They select tuples from the view
internet_incfor which their value for theiinc_idattribute is within the range of 2 and 4 (inclusive):SELECT * FROM internet_inc WHERE iinc_id between 2 AND 4
~: The evaluation of this operator returns a value between 0 and 1 that estimates the similarity between the two text-type operands using a variety of similarity algorithms. In addition to the operands to compare, the similarity operator receives the similarity algorithm to use and a minimum similarity threshold as parameters.Where the similarity between character strings reaches or exceeds the threshold, the condition is assessed as true. Where this is not the case, it is assessed as false.
The left-hand (text-type) operand is one of the character strings to compare. The right-hand operand is a list of text-type elements. The first element in this list is the second character string to compare. The second specifies the minimum similarity threshold (a value of between 0 and 1) and the third (optional) specifies the similarity algorithm to be used.
The algorithms available are the same as for the similarity function (see appendix SIMILARITY).
Example: The following query returns tuples for which their
customernamefield has a similarity of over 0.7 with the “General Motors Inc” string, using the Jaro Winkler editing distance algorithm between strings:SELECT * FROM internet_inc_cname WHERE customer_name ~ ('General Motors Inc','0.7','JaroWinkler')
XMLExists: This operator executes an XQuery expression (XML Query) over anxmlvalue. It returns true if it finds a match. This operator has three signatures:XMLExists(XQueryExpression : text, value : xml)
Returns
trueif there is a match ofXQueryExpressioninvalue.XMLExists(XQueryExpression : text, ReadXQueryExpressionFromFile : boolean, value : xml)
If
ReadXQueryExpressionFromFileistrue,XQueryExpressionis a path to a file that contains the XQuery expression.XMLExists(XQueryExpression : text, ReadXQueryExpressionFromFile : boolean, value : xml, ReadXMLValueFromFile)
If
ReadXQueryExpressionFromFileistrue,XQueryExpressionhas to be a path to a file that contains the XQuery expression.If
ReadXMLValueFromFileistrue,ReadXMLValueFromFilehas to be path to a file that contains the input XML.
