forked from docs/doc-exports
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>
64 lines
9.2 KiB
HTML
64 lines
9.2 KiB
HTML
<a name="mrs_01_1439"></a><a name="mrs_01_1439"></a>
|
|
|
|
<h1 class="topictitle1">UPDATE CARBON TABLE</h1>
|
|
<div id="body1595920212821"><div class="section" id="mrs_01_1439__s56e6e636e92d4e25ba86171d168a0097"><h4 class="sectiontitle">Function</h4><p id="mrs_01_1439__a36526b302fb741da8affa982ede0120e">This command is used to update the CarbonData table based on the column expression and optional filtering conditions.</p>
|
|
</div>
|
|
<div class="section" id="mrs_01_1439__sc17acc5cdde24923afe02ad70c5af9a1"><h4 class="sectiontitle">Syntax</h4><ul id="mrs_01_1439__u53fee6cb19734e60b97687352a5b1f66"><li id="mrs_01_1439__l1c214f65d2194a2b865d5b10b4f14382">Syntax 1:<p id="mrs_01_1439__a200ede54202d40e89dda74cc700ff250"><a name="mrs_01_1439__l1c214f65d2194a2b865d5b10b4f14382"></a><a name="l1c214f65d2194a2b865d5b10b4f14382"></a><b><span class="cmdname" id="mrs_01_1439__cmdname5746349121615">UPDATE <CARBON TABLE> SET (column_name1, column_name2, ... column_name n) = (column1_expression , column2_expression , column3_expression ... column n_expression ) [ WHERE { <filter_condition> } ];</span></b></p>
|
|
</li><li id="mrs_01_1439__l0227115acbb24001b6eeea4df6be6a92">Syntax 2:<p id="mrs_01_1439__a3143892d19674a12b83e499eea8c0092"><a name="mrs_01_1439__l0227115acbb24001b6eeea4df6be6a92"></a><a name="l0227115acbb24001b6eeea4df6be6a92"></a><b><span class="cmdname" id="mrs_01_1439__cmdname20169353181610">UPDATE <CARBON TABLE> SET (column_name1, column_name2,) = (select sourceColumn1, sourceColumn2 from sourceTable [ WHERE { <filter_condition> } ] ) [ WHERE { <filter_condition> } ];</span></b></p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="mrs_01_1439__s237e949a91f645afb133fa8ff1fb3a30"><h4 class="sectiontitle">Parameter Description</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_1439__tbf6ea26f1d504556bc00eb71921b92b0" frame="border" border="1" rules="all"><caption><b>Table 1 </b>UPDATE parameters</caption><thead align="left"><tr id="mrs_01_1439__rddbab88c4e884027b074774928deec85"><th align="left" class="cellrowborder" valign="top" width="23.68%" id="mcps1.3.3.2.2.3.1.1"><p id="mrs_01_1439__abdf5d12b11d4467b97baafd3fcebca8a">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="76.32%" id="mcps1.3.3.2.2.3.1.2"><p id="mrs_01_1439__ab3ad580270924283937a10d484199525">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="mrs_01_1439__r34842d652b5a49c59aca88bb0efdaaed"><td class="cellrowborder" valign="top" width="23.68%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1439__a415fa4ab88554922af1ee1285180ce94">CARBON TABLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="76.32%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1439__ac9347142ecb343fea4e8122e01b659b5">Name of the CarbonData table to be updated</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_1439__r0166cc86ce3746eaa8c8928e6c025dfa"><td class="cellrowborder" valign="top" width="23.68%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1439__a85891954f0a74d868c132592dbd9058c">column_name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="76.32%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1439__a03ee028b6d254b31a7e4c55a25c89dd8">Target column to be updated</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_1439__r64bff89c5c8a4ae6892cb5a840fffb35"><td class="cellrowborder" valign="top" width="23.68%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1439__a4510eadd622d4c0a801314f75c488055">sourceColumn</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="76.32%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1439__aa6bd0f68abfc4790b37d9f105798cb8c">Column value of the source table that needs to be updated in the target table</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="mrs_01_1439__rb8c1d302640a4adba6c2d6734fc67c64"><td class="cellrowborder" valign="top" width="23.68%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1439__ab1fb0c8c5f6e43b5b114c95c03c61d33">sourceTable</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="76.32%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1439__ab1c5ec4aea1b4c27a7d82ad2c09dad28">Table from which the records are updated to the target table</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="mrs_01_1439__sd4125e30a7ec4747a8c465bccd8549bf"><h4 class="sectiontitle">Precautions</h4><p id="mrs_01_1439__a895370cb5a824e3f83bfa038b2351754">Note the following before running this command:</p>
|
|
<ul id="mrs_01_1439__u7975b5246fce4b358c07a07f4f05df19"><li id="mrs_01_1439__l1ac8d77fd63f42d3a30ae60c35b7f884">The UPDATE command fails if multiple input rows in the source table are matched with a single row in the target table.</li><li id="mrs_01_1439__lc6bede03d4cf4322add979e5525b27bd">If the source table generates empty records, the UPDATE operation completes without updating the table.</li><li id="mrs_01_1439__l227800111e174b4ca515dcc0f51fca55">If rows in the source table do not match any existing rows in the target table, the UPDATE operation completes without updating the table.</li><li id="mrs_01_1439__lcc21c98be172414aa35a5a671af6fc4a">UPDATE is not allowed in the table with secondary index.</li><li id="mrs_01_1439__l8e46bb3ea76f4773af297e69d76aa6be">In a subquery, if the source table and target table are the same, the UPDATE operation fails.</li><li id="mrs_01_1439__la3f79cd4337447e4b64e60dde2f03060">The UPDATE operation fails if the subquery used in the UPDATE command contains an aggregate function or a GROUP BY clause.<p id="mrs_01_1439__a126d3a1c4264495490601c25a212bbbe"><a name="mrs_01_1439__la3f79cd4337447e4b64e60dde2f03060"></a><a name="la3f79cd4337447e4b64e60dde2f03060"></a>For example, <b><span class="cmdname" id="mrs_01_1439__cmdname3162115931619">update t_carbn01 a set (a.item_type_code, a.profit) = ( select b.item_type_cd, sum(b.profit) from t_carbn01b b where item_type_cd =2 group by item_type_code);</span></b>.</p>
|
|
<p id="mrs_01_1439__ac00cdaa8ab7f422fa087971bccb3a64f">In the preceding example, aggregate function <strong id="mrs_01_1439__b437911818517">sum(b.profit)</strong> and GROUP BY clause are used in the subquery. As a result, the UPDATE operation will fail.</p>
|
|
</li><li id="mrs_01_1439__la1e70e489bb34f4ead7eb5cb020da9f7">If the <strong id="mrs_01_1439__b1613491617519">carbon.input.segments</strong> property has been set for the queried table, the UPDATE operation fails. To solve this problem, run the following statement before the query:<p id="mrs_01_1439__ae45994fbfe4745009e8c3106034a40ea">Syntax:</p>
|
|
<p id="mrs_01_1439__a0dbd4892987442c99ded02e37f7701e5"><strong id="mrs_01_1439__a5d9cccf792ff4511a1f4bafedaf93932">SET carbon.input.segments. <database_name>. <table_name>=*</strong>;</p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="mrs_01_1439__sb848b6b6f29c4ca89355bd1310c46e8b"><h4 class="sectiontitle">Examples</h4><ul id="mrs_01_1439__u0312973023754beda1ab729c6a2d7c0e"><li id="mrs_01_1439__l4404b8acfc17475fb366d887b5089728">Example 1:<p id="mrs_01_1439__a50d2b792e29d4b378b534e7536188653"><a name="mrs_01_1439__l4404b8acfc17475fb366d887b5089728"></a><a name="l4404b8acfc17475fb366d887b5089728"></a><b><span class="cmdname" id="mrs_01_1439__cmdname14961238176">update carbonTable1 d set (d.column3,d.column5 ) = (select s.c33 ,s.c55 from sourceTable1 s where d.column1 = s.c11) where d.column1 = 'country' exists( select * from table3 o where o.c2 > 1);</span></b></p>
|
|
</li><li id="mrs_01_1439__l50a92da8bcff45e69d94acd5f91a93b5">Example 2:<p id="mrs_01_1439__a5bdc1baa429e4d888e316d36f974b849"><a name="mrs_01_1439__l50a92da8bcff45e69d94acd5f91a93b5"></a><a name="l50a92da8bcff45e69d94acd5f91a93b5"></a><b><span class="cmdname" id="mrs_01_1439__cmdname127112612175">update carbonTable1 d set (c3) = (select s.c33 from sourceTable1 s where d.column1 = s.c11) where exists( select * from iud.other o where o.c2 > 1);</span></b></p>
|
|
</li><li id="mrs_01_1439__lb3a9b663caad497f866669c8a098ef98">Example 3:<p id="mrs_01_1439__ab68106f0d77f48f3a1a3c30cdba6c22a"><a name="mrs_01_1439__lb3a9b663caad497f866669c8a098ef98"></a><a name="lb3a9b663caad497f866669c8a098ef98"></a><b><span class="cmdname" id="mrs_01_1439__cmdname19245171131718">update carbonTable1 set (c2, c5 ) = (c2 + 1, concat(c5 , "y" ));</span></b></p>
|
|
</li><li id="mrs_01_1439__l5f3aa3f45e5b4b28923863de0ee4fbdd">Example 4:<p id="mrs_01_1439__ae9734985b099486aa5701c635f64cc77"><a name="mrs_01_1439__l5f3aa3f45e5b4b28923863de0ee4fbdd"></a><a name="l5f3aa3f45e5b4b28923863de0ee4fbdd"></a><b><span class="cmdname" id="mrs_01_1439__cmdname157348141174">update carbonTable1 d set (c2, c5 ) = (c2 + 1, "xyx") where d.column1 = 'india';</span></b></p>
|
|
</li><li id="mrs_01_1439__l67a9394328f944078c433cfae443b9e6">Example 5:<p id="mrs_01_1439__a06583a4f329d4d778b56cc17cf878697"><a name="mrs_01_1439__l67a9394328f944078c433cfae443b9e6"></a><a name="l67a9394328f944078c433cfae443b9e6"></a><b><span class="cmdname" id="mrs_01_1439__cmdname1693151819171">update carbonTable1 d set (c2, c5 ) = (c2 + 1, "xyx") where d.column1 = 'india' and exists( select * from table3 o where o.column2 > 1);</span></b></p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="mrs_01_1439__s49b19580d9be445b92aafa75822ad7a2"><h4 class="sectiontitle">System Response</h4><p id="mrs_01_1439__a14f5dd2a5132480991d1f4c428544d79">Success or failure will be recorded in the driver log and on the client.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_1437.html">DML</a></div>
|
|
</div>
|
|
</div>
|
|
|