<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/Type+Conversions">Type Conversions</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~shawkins">Steven Hawkins</a>
    </h4>
        <br/>
                         <h4>Changes (7)</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" >* Situations involving literal values that would normally require explicit conversions may have the explicit conversion applied implicitly if no loss of information occurs. <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">* When Teiid detects that an explicit conversion can not be applied implicitly in criteria, the criteria will be treated as false.  <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">* If [widenComparisonToString|System Properties] is false (the default), when Teiid detects that an explicit conversion can not be applied implicitly in criteria, then an exception will be raised.  If [widenComparisonToString|System Properties] is true, then depending upon the comparison a widening conversion will be applied or the criteria will be treated as false.  <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">* Array conversions are currently only valid to and from compatible object arrays.  It is not yet possible for example to cast from integer[] to long[]. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >For example: <br></td></tr>
            <tr><td class="diff-changed-lines" >{code:SQL}SELECT * FROM my.table WHERE created_by = <span class="diff-changed-words"><span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">‘</span><span class="diff-added-chars"style="background-color: #dfd;">&#39;</span>not</span> a <span class="diff-changed-words">date<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">’</span><span class="diff-added-chars"style="background-color: #dfd;">&#39;</span>{code}</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Given that created\_by is typed as date, rather than converting &#39;not a date&#39; to a date value, the criteria will remain as a string comparison and therefore be false. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">With [widenComparisonToString|System Properties] as false and created\_by is typed as date, rather than converting &#39;not a date&#39; to a date value, an exception will be raised. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">* Array conversions are currently only valid to and from compatible object arrays.  It is not yet possible for example to cast from integer[] to long[]. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >* Explicit conversions that are not allowed between two types will result in an exception before execution. Allowed explicit conversions may still fail during processing if the runtime values are not actually convertable. <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>Data types may be converted from one form to another either explicitly or implicitly. Implicit conversions automatically occur in criteria and expressions to ease development. Explicit datatype conversions require the use of the <b>CONVERT</b> function or <b>CAST</b> keyword.</p>

<p>Type Conversion Considerations:</p>

<ul>
        <li>Any type may be implicitly converted to the OBJECT type.</li>
</ul>


<ul>
        <li>The OBJECT type may be explicitly converted to any other type.</li>
</ul>


<ul>
        <li>The NULL value may be converted to any type.</li>
</ul>


<ul>
        <li>Any valid implicit conversion is also a valid explicit conversion.</li>
</ul>


<ul>
        <li>Situations involving literal values that would normally require explicit conversions may have the explicit conversion applied implicitly if no loss of information occurs.</li>
</ul>


<ul>
        <li>If <a href="/author/display/TEIID/System+Properties" title="System Properties">widenComparisonToString</a> is false (the default), when Teiid detects that an explicit conversion can not be applied implicitly in criteria, then an exception will be raised.  If <a href="/author/display/TEIID/System+Properties" title="System Properties">widenComparisonToString</a> is true, then depending upon the comparison a widening conversion will be applied or the criteria will be treated as false.</li>
</ul>


<p>For example:</p>
<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;">SELECT * FROM my.table WHERE created_by = 'not a date'</pre>
</div></div>

<p>With <a href="/author/display/TEIID/System+Properties" title="System Properties">widenComparisonToString</a> as false and created&#95;by is typed as date, rather than converting 'not a date' to a date value, an exception will be raised.</p>

<ul>
        <li>Array conversions are currently only valid to and from compatible object arrays.  It is not yet possible for example to cast from integer[] to long[].</li>
</ul>


<ul>
        <li>Explicit conversions that are not allowed between two types will result in an exception before execution. Allowed explicit conversions may still fail during processing if the runtime values are not actually convertable.</li>
</ul>


<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Warning</b><br />The Teiid conversions of float/double/bigdecimal/timestamp to string rely on the JDBC/Java defined output formats.  Pushdown behavior attempts to mimic these results, but may vary depending upon the actual source type and conversion logic.  Care should be taken to not assume the string form in criteria or other places where a variation may cause different results.</td></tr></table></div>


<div class='scroll-title-macro'><div class='scroll-title-body'></div><div class='scroll-title'><strong>Type Conversions</strong></div></div>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Source Type</th>
<th class='confluenceTh'>Valid Implicit Target Types</th>
<th class='confluenceTh'>Valid Explicit Target Types</th>
</tr>
<tr>
<td class='confluenceTd'>string</td>
<td class='confluenceTd'>clob</td>
<td class='confluenceTd'>char, boolean, byte, short, integer, long, biginteger, float, double, bigdecimal, xml [a]</td>
</tr>
<tr>
<td class='confluenceTd'>char</td>
<td class='confluenceTd'>string</td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'>boolean</td>
<td class='confluenceTd'>string, byte, short, integer, long, biginteger, float, double, bigdecimal</td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'>byte</td>
<td class='confluenceTd'>string, short, integer, long, biginteger, float, double, bigdecimal</td>
<td class='confluenceTd'>boolean</td>
</tr>
<tr>
<td class='confluenceTd'>short</td>
<td class='confluenceTd'>string, integer, long, biginteger, float, double, bigdecimal</td>
<td class='confluenceTd'>boolean, byte</td>
</tr>
<tr>
<td class='confluenceTd'>integer</td>
<td class='confluenceTd'>string, long, biginteger, double, bigdecimal</td>
<td class='confluenceTd'>boolean, byte, short, float</td>
</tr>
<tr>
<td class='confluenceTd'>long</td>
<td class='confluenceTd'>string, biginteger, bigdecimal</td>
<td class='confluenceTd'>boolean, byte, short, integer, float, double</td>
</tr>
<tr>
<td class='confluenceTd'>biginteger</td>
<td class='confluenceTd'>string, bigdecimal</td>
<td class='confluenceTd'>boolean, byte, short, integer, long, float, double</td>
</tr>
<tr>
<td class='confluenceTd'>bigdecimal</td>
<td class='confluenceTd'>string</td>
<td class='confluenceTd'>boolean, byte, short, integer, long, biginteger, float, double</td>
</tr>
<tr>
<td class='confluenceTd'>float</td>
<td class='confluenceTd'>string, bigdecimal, double</td>
<td class='confluenceTd'>boolean, byte, short, integer, long, biginteger</td>
</tr>
<tr>
<td class='confluenceTd'>double</td>
<td class='confluenceTd'>string, bigdecimal</td>
<td class='confluenceTd'>boolean, byte, short, integer, long, biginteger, float</td>
</tr>
<tr>
<td class='confluenceTd'>date</td>
<td class='confluenceTd'>string, timestamp</td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'>time</td>
<td class='confluenceTd'>string, timestamp</td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'>timestamp</td>
<td class='confluenceTd'>string</td>
<td class='confluenceTd'>date, time</td>
</tr>
<tr>
<td class='confluenceTd'>clob</td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>string</td>
</tr>
<tr>
<td class='confluenceTd'>xml</td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>string [b]</td>
</tr>
</tbody></table>
</div>



<p>[a] string to xml is equivalent to XMLPARSE&#40;DOCUMENT exp) - See also <a href="/author/display/TEIID/XML+Functions#XMLFunctions-XMLPARSE">XML Functions#XMLPARSE</a><br/>
[b] xml to string is equivalent to XMLSERIALIZE&#40;exp AS STRING) - see also <a href="/author/display/TEIID/XML+Functions#XMLFunctions-XMLSERIALIZE">XML Functions#XMLSERIALIZE</a></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/Type+Conversions">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=18646247&revisedVersion=8&originalVersion=7">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Type+Conversions?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>