<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 (3)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >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 *CONVERT* function or *CAST* keyword. <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >Type Conversion <span class="diff-changed-words">Considerations<span class="diff-added-chars"style="background-color: #dfd;">:</span></span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br>* Any type may be implicitly converted to the OBJECT type. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >* When Teiid detects that an explicit conversion can not be applied implicitly in criteria, the criteria will be treated as false.  <br> <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" >For example: <br>{code:SQL}SELECT * FROM my.table WHERE created_by = ‘not a date’{code} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >\[a] string to xml is <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">equivlant</span> <span class="diff-added-words"style="background-color: #dfd;">equivalent</span> to XMLPARSE\(DOCUMENT exp) - See also [XML Functions#XMLPARSE] <br></td></tr>
            <tr><td class="diff-unchanged" >\[b] xml to string is equivalent to XMLSERIALIZE\(exp AS STRING) - see also [XML Functions#XMLSERIALIZE] <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>When Teiid detects that an explicit conversion can not be applied implicitly in criteria, the criteria will be treated as false.</li>
</ul>


<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>


<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>Given that created&#95;by is typed as date, rather than converting 'not a date' to a date value, the criteria will remain as a string comparison and therefore be false.</p>

<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'>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=6&originalVersion=5">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>