Yang, Tong 6182f91ba8 MRS component operation guide_normal 2.0.38.SP20 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2022-12-09 14:55:21 +00:00

30 lines
3.9 KiB
HTML

<a name="mrs_01_1461"></a><a name="mrs_01_1461"></a>
<h1 class="topictitle1">Why Does INSERT INTO CARBON TABLE Command Fail?</h1>
<div id="body1595920215964"><div class="section" id="mrs_01_1461__s7ed1a7513a7149b192c79f4550281527"><h4 class="sectiontitle">Question</h4><p id="mrs_01_1461__a42e7de655764425a95cb64787cfbb093">Why does the <i><b><span class="cmdname" style="font-family:Arial" id="mrs_01_1461__c98f11555cae8481199951a1df92e35ec">INSERT INTO CARBON TABLE</span></b></i> command fail and the following error message is displayed?</p>
<pre class="screen" id="mrs_01_1461__s23ebaeedfe3c4731842c45810205b2f8">Data load failed due to bad record</pre>
</div>
<div class="section" id="mrs_01_1461__sad0929cd78fa440c88420d2c704f6102"><h4 class="sectiontitle">Answer</h4><p id="mrs_01_1461__adb05ba855e6f4b2485d8d94c4d9244d7">The <i><b><span class="cmdname" style="font-family:Arial" id="mrs_01_1461__c69a2be218a0443e6b3aa358b61321c0f">INSERT INTO CARBON TABLE</span></b></i> command fails in the following scenarios:</p>
</div>
<ul id="mrs_01_1461__ubd8e024948184fca9ff6ed769961bc13"><li id="mrs_01_1461__l18b5fe63052f4fc7be5de61474be0e92">If the data type of source and target table columns are not the same, the data from the source table will be treated as bad records and the <i><b><span class="cmdname" style="font-family:Arial" id="mrs_01_1461__c76cfe7c9ee4546a6886c63b53aedea27">INSERT INTO</span></b></i> command fails.</li><li id="mrs_01_1461__lb753a469ae8a4f7d99e3dafe23d1a9f8">If the result of aggregation function on a source column exceeds the maximum range of the target column, then the <i><b><span class="cmdname" style="font-family:Arial" id="mrs_01_1461__c733c7810932a40b78db3047e32a4d1ea">INSERT INTO</span></b></i> command fails.<p id="mrs_01_1461__ac56c85f311fd4b068b201fb6ab83d403">Solution:</p>
<p id="mrs_01_1461__aafaea907fd3749a5a341667d02909943">You can use the cast function on corresponding columns when inserting records.</p>
<p id="mrs_01_1461__a05974f917b01406a8b36e36cf6c46eb8">For example:</p>
<ol id="mrs_01_1461__o08312a05d53a45daa1caee65722989fc"><li id="mrs_01_1461__l46beb72a8d804f6db80eb3b11964ea8d">Run the <i><b><span class="cmdname" style="font-family:Arial" id="mrs_01_1461__cc87b964b800a4c23aa4a8944baf36689">DESCRIBE</span></b></i> command to query the target and source table.<p id="mrs_01_1461__adac29c4ea93240818b233c946c430b5c"><i><b><span class="cmdname" style="font-family:Arial" id="mrs_01_1461__c4b7ffc6f387b4be68fe28332c8ea631f">DESCRIBE</span></b></i> <i><span class="varname" id="mrs_01_1461__vbcc207ebe479410abc4b5ddd7e698ebc">newcarbontable</span></i>;</p>
<p id="mrs_01_1461__ad1f3bfa8701e4084908e1e1c5d3f3434">Result:</p>
<pre class="screen" id="mrs_01_1461__s47026e2451464bf381ca5d3bba057d9e">col1 int
col2 bigint</pre>
<p id="mrs_01_1461__a37ca2ac20ad8411c94732cd61e898649"><i><b><span class="cmdname" style="font-family:Arial" id="mrs_01_1461__c3d2daa9481054e0fb7fd562e3ca7889f">DESCRIBE</span></b></i> <i><span class="varname" id="mrs_01_1461__v8813f8037b2c48b3bce528744ca5e2d8">sourcetable</span></i>;</p>
<p id="mrs_01_1461__a083516a4134944f4a4c776eb34783a43">Result:</p>
<pre class="screen" id="mrs_01_1461__sd96c9767a29442498c9df782f9859d3b">col1 int
col2 int</pre>
</li><li id="mrs_01_1461__l9ab04704eaf04b4ebc106c55761a5670">Add the cast function to convert bigint value to integer.<p id="mrs_01_1461__a5dbb594f633e41f98e0404934efc6229"><a name="mrs_01_1461__l9ab04704eaf04b4ebc106c55761a5670"></a><a name="l9ab04704eaf04b4ebc106c55761a5670"></a><i><b><span class="cmdname" style="font-family:Arial" id="mrs_01_1461__c4a80134b70c7460f940b9d873903fadd">INSERT INTO</span></b></i> <i><span class="varname" id="mrs_01_1461__v541c192f9e1a426591737e2b3747caf5">newcarbontable select col1, cast(col2 as integer) from sourcetable;</span></i></p>
</li></ol>
</li></ul>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_1457.html">CarbonData FAQ</a></div>
</div>
</div>