<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/Criteria">Criteria</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~shawkins">Steven Hawkins</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >* {code:SQL}(criteria){code} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >* {code:SQL}expression (=|&lt;&gt;|!=|&lt;|&gt;|&lt;=|&gt;=) (expression|((ANY|ALL|SOME) <span class="diff-changed-words">subquery<span class="diff-added-chars"style="background-color: #dfd;">|(array_expression</span>))<span class="diff-added-chars"style="background-color: #dfd;">)</span>{code}</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br>* {code:SQL}expression [NOT] IS NULL{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>Criteria may be:</p>

<ul>
        <li>Predicates that evaluate to true or false</li>
</ul>


<ul>
        <li>Logical criteria that combines criteria (AND, OR, NOT)</li>
</ul>


<ul>
        <li>A value expression with type boolean</li>
</ul>


<p>Usage:</p>

<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">criteria AND|OR criteria</pre>
</div></div></li>
</ul>


<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">NOT criteria</pre>
</div></div></li>
</ul>


<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">(criteria)</pre>
</div></div></li>
</ul>


<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">expression (=|&lt;&gt;|!=|&lt;|&gt;|&lt;=|&gt;=) (expression|((ANY|ALL|SOME) subquery|(array_expression)))</pre>
</div></div></li>
</ul>


<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">expression [NOT] IS NULL</pre>
</div></div></li>
</ul>


<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">expression [NOT] IN (expression [,expression]*)|subquery</pre>
</div></div></li>
</ul>


<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">expression [NOT] LIKE pattern [ESCAPE char]</pre>
</div></div></li>
</ul>


<p>Matches the string expression against the given string pattern. The pattern may contain % to match any number of characters and _ to match any single character.  The escape character can be used to escape the match characters % and &#95;.</p>

<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">expression [NOT] SIMILAR TO pattern [ESCAPE char]</pre>
</div></div></li>
</ul>


<p>SIMILAR TO is a cross between LIKE and standard regular expression syntax.  % and _ are still used, rather than .&#42; and . respectively.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Note</b><br />Teiid does not exhaustively validate SIMILAR TO pattern values.  Rather the pattern is converted to an equivalent regular expression. Care should be taken not to rely on general regular expression features when using SIMILAR TO.  If additional features are needed, then LIKE_REGEX should be used. Usage of a non-literal pattern is discouraged as pushdown support is limited.</td></tr></table></div>

<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">expression [NOT] LIKE_REGEX pattern</pre>
</div></div></li>
</ul>


<p>LIKE_REGEX allows for standard regular expression syntax to be used for matching.  This differs from SIMILAR TO and LIKE in that the escape character is no longer used (\ is already the standard escape mechanism in regular expressions and % and _ have no special meaning. The runtime engine uses the JRE implementation of regular expressions - see the <a href="http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html" class="external-link" rel="nofollow">java.util.regex.Pattern</a> class for details.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Note</b><br />Teiid does not exhaustively validate LIKE_REGEX pattern values.  It is possible to use JRE only regular expression features that are not specified by the SQL specification.  Additional not all sources support the same regular expression flavor or extensions.  Care should be taken in pushdown situations to ensure that the pattern used will have same meaning in Teiid and across all applicable sources.</td></tr></table></div>

<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">EXISTS (subquery)</pre>
</div></div></li>
</ul>


<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">expression [NOT] BETWEEN minExpression AND maxExpression</pre>
</div></div></li>
</ul>


<p>Teiid converts BETWEEN into the equivalent form expression &gt;= minExpression AND expression &lt;= maxExpression</p>

<ul>
        <li><div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">expression</pre>
</div></div></li>
</ul>


<p>Where expression has type boolean.</p>

<p>Syntax Rules:</p>

<ul>
        <li>The precedence ordering from lowest to highest is comparison, NOT, AND, OR</li>
</ul>


<ul>
        <li>Criteria nested by parenthesis will be logically evaluated prior to evaluating the parent criteria.</li>
</ul>


<p>Some examples of valid criteria are:</p>

<ul>
        <li>(balance &gt; 2500.0)</li>
</ul>


<ul>
        <li>100*(50 - x)/(25 - y) &gt; z</li>
</ul>


<ul>
        <li>concat(areaCode,concat('-',phone)) LIKE '314%1'</li>
</ul>


<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Comparing null Values</b><br />Null values represent an unknown value. Comparison with a null value will evaluate to 'unknown', which can never be true even if 'not' is used.</td></tr></table></div>

<h1><a name="Criteria-CriteriaPrecedence"></a>Criteria Precedence</h1>

<p>Teiid parses and evaluates conditions with higher precedence before those with lower precedence. Conditions with equal  precedence are left associative. Condition precedence listed from high to low:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Condition </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> sql operators </td>
<td class='confluenceTd'> See <a href="/author/display/TEIID/Expressions" title="Expressions">Expressions</a><br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> EXISTS, LIKE, SIMILAR TO, LIKE_REGEX, BETWEEN, IN, IS NULL, &lt;, &lt;=, &gt;, &gt;=, =, &lt;&gt; </td>
<td class='confluenceTd'> comparison </td>
</tr>
<tr>
<td class='confluenceTd'> NOT </td>
<td class='confluenceTd'> negation </td>
</tr>
<tr>
<td class='confluenceTd'> AND </td>
<td class='confluenceTd'> conjunction </td>
</tr>
<tr>
<td class='confluenceTd'> OR </td>
<td class='confluenceTd'> disjunction </td>
</tr>
</tbody></table>
</div>

<p>Note however that to prevent lookaheads the parser does not accept all possible criteria sequences.&nbsp; For example "a = b is null" is not accepted, since by the left associative parsing we first recognize "a =", then look for a common value expression.&nbsp; "b is null" is not a valid common value expression.&nbsp; Thus nesting must be used, for example "(a = b) is null".&nbsp; See <a href="/author/display/TEIID/BNF+for+SQL+Grammar" title="BNF for SQL Grammar">BNF for SQL Grammar</a> for all parsing rules.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/Criteria">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=18646219&revisedVersion=7&originalVersion=6">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Criteria?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>