forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
139 lines
32 KiB
HTML
139 lines
32 KiB
HTML
<a name="EN-US_TOPIC_0000001233563247"></a><a name="EN-US_TOPIC_0000001233563247"></a>
|
|
|
|
<h1 class="topictitle1">Using a gsql Meta-Command to Import Data</h1>
|
|
<div id="body8662426"><p id="EN-US_TOPIC_0000001233563247__en-us_topic_0117407672_p8060118">The <strong id="EN-US_TOPIC_0000001233563247__b842352706161045">gsql</strong> tool of <span id="EN-US_TOPIC_0000001233563247__text1495556173">GaussDB(DWS)</span> provides the <strong id="EN-US_TOPIC_0000001233563247__b842352706161054">\copy</strong> meta-command to import data.</p>
|
|
<div class="section" id="EN-US_TOPIC_0000001233563247__sf746a4145f69425a8fed6cd731fa1c73"><h4 class="sectiontitle">\copy Command</h4><p id="EN-US_TOPIC_0000001233563247__a3944ce1fb873406986d7f302af63b107">For details about the <strong id="EN-US_TOPIC_0000001233563247__b842352706161155">\copy</strong> command, see <a href="#EN-US_TOPIC_0000001233563247__t3ed8c97d36d74d0da906d0f028ff707c">Table 1</a>.</p>
|
|
|
|
<div class="tablenoborder"><a name="EN-US_TOPIC_0000001233563247__t3ed8c97d36d74d0da906d0f028ff707c"></a><a name="t3ed8c97d36d74d0da906d0f028ff707c"></a><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001233563247__t3ed8c97d36d74d0da906d0f028ff707c" frame="border" border="1" rules="all"><caption><b>Table 1 </b>\copy meta-command</caption><thead align="left"><tr id="EN-US_TOPIC_0000001233563247__r99153637f54f4056b6cb80bc978f2fd3"><th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.2.3.2.3.1.1"><p id="EN-US_TOPIC_0000001233563247__ad777dd7511274d14ac37d91b6d65758b">Syntax</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.2.3.2.3.1.2"><p id="EN-US_TOPIC_0000001233563247__a512a9f68fb614626a3f76898fca8169d">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001233563247__r55272a0d12574f16bfc85267727ec3a3"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.2.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233563247__a9b33a29fb1964002b33741ccab87c94f">\copy { table [ ( column_list ) ] |</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a2eff49f7c0994b4e8b2b1d985f3a3682">( query ) } { from | to } { filename |</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a52fefc833a8346bfb29ba7257e7918e4">stdin | stdout | pstdin | pstdout }</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a51e7d3731a8846e5be5a4589451bbabe">[ with ] [ binary ] [ oids ] [ delimiter</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__ab62f3d207b4c4a748b098586bbec5b34">[ as ] 'character' ] [ null [ as ] 'string' ]</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0117407672_p743422203715">[ csv [ header ] [ quote [ as ]</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a23be8b5fee814840b88c8286992172f8">'character' ] [ escape [ as ] 'character' ]</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a2d851f2842874a9a893312d63cafdad9">[ force quote column_list | * ] [ force</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a9d802a2b0b644205af49c2564021b773">not null column_list ] ]</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.2.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233563247__a06659e8d0c924004824c8632a065a788">You can run this command to import or export data after logging in to the database on any gsql client. Different from the <strong id="EN-US_TOPIC_0000001233563247__b842352706193229">COPY</strong> statement in SQL, this command performs read/write operations on local files rather than files on database servers. The accessibility and permissions of the local files are restricted to local users.</p>
|
|
<div class="note" id="EN-US_TOPIC_0000001233563247__note1924115273417"><span class="notetitle"> NOTE: </span><div class="notebody"><p id="EN-US_TOPIC_0000001233563247__p1925145210348"><strong id="EN-US_TOPIC_0000001233563247__b1982719177018">\copy</strong> only applies to small-batch data import with uniform formats but poor error tolerance capability. GDS or <strong id="EN-US_TOPIC_0000001233563247__b858118190013">COPY</strong> is preferred for data import.</p>
|
|
</div></div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001233563247__s1245c46236a345578ea1ca23745b89a8"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001233563247__udb8f0b0d03cd4f44b0e8b539c679eb9f"><li id="EN-US_TOPIC_0000001233563247__l8eaa3c0df20748e19d2b74ce2eeeaf50">table<p id="EN-US_TOPIC_0000001233563247__a489f17df673e4c65bac15ca39fabf192"><a name="EN-US_TOPIC_0000001233563247__l8eaa3c0df20748e19d2b74ce2eeeaf50"></a><a name="l8eaa3c0df20748e19d2b74ce2eeeaf50"></a>Specifies the name (possibly schema-qualified) of an existing table.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__ae26d0b46980940b2bfc02c0345cca6d4">Value range: an existing table name</p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__lc933bf2c53024c3b82adb73e2e23547a">column_list<p id="EN-US_TOPIC_0000001233563247__a6020bce9071d43ba87682ec7f3ec9397"><a name="EN-US_TOPIC_0000001233563247__lc933bf2c53024c3b82adb73e2e23547a"></a><a name="lc933bf2c53024c3b82adb73e2e23547a"></a>Specifies an optional list of columns to be copied.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a62b958b42f004d68a464ea163bdca40d">Value range: any field in the table. If the column list is not specified, all columns in the table will be copied.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l9777e2a118ae446b923d0dfb040aa5a6">query<p id="EN-US_TOPIC_0000001233563247__a6adc2220b11943ffaf4d2fc412d4a485"><a name="EN-US_TOPIC_0000001233563247__l9777e2a118ae446b923d0dfb040aa5a6"></a><a name="l9777e2a118ae446b923d0dfb040aa5a6"></a>Specifies that the results will be copied.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a6935f54e6ef14bf598b81758a1a346c0">Valid value: a <strong id="EN-US_TOPIC_0000001233563247__b1011483211384">SELECT</strong> or <strong id="EN-US_TOPIC_0000001233563247__b1399504011384">VALUES</strong> command in parentheses.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l7b31f4fca4a443858543483512188d44">filename<p id="EN-US_TOPIC_0000001233563247__a2158e33ba7fa4220a20c0efeed62a2f6"><a name="EN-US_TOPIC_0000001233563247__l7b31f4fca4a443858543483512188d44"></a><a name="l7b31f4fca4a443858543483512188d44"></a>Specifies the absolute path of a file. To run the <strong id="EN-US_TOPIC_0000001233563247__b842352706161825">\copy</strong> command, the user must have the write permission for this path.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l5a8b8ec8d3b84b1d8d19a91682dda8d7">stdin<p id="EN-US_TOPIC_0000001233563247__a1ad941b7e98d4dd6b473cf7c67921d99"><a name="EN-US_TOPIC_0000001233563247__l5a8b8ec8d3b84b1d8d19a91682dda8d7"></a><a name="l5a8b8ec8d3b84b1d8d19a91682dda8d7"></a>Specifies that input comes from the client application.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__lf64488d094ef478db81a047e9e9d48f6">stdout<p id="EN-US_TOPIC_0000001233563247__aae03039c253e4f7d915e5a3a4ea231f8"><a name="EN-US_TOPIC_0000001233563247__lf64488d094ef478db81a047e9e9d48f6"></a><a name="lf64488d094ef478db81a047e9e9d48f6"></a>Specifies that output goes to the client application.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__le90e6bb67b994dca904cc633bedb707d">pstdin<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0117407672_p540453024920"><a name="EN-US_TOPIC_0000001233563247__le90e6bb67b994dca904cc633bedb707d"></a><a name="le90e6bb67b994dca904cc633bedb707d"></a>Specifies that input comes from the gsql client.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l7285de9fa0fe46a98dc94b9ae8fc4b01">pstout</li><li id="EN-US_TOPIC_0000001233563247__l1286779a7feb46a0870b9a9372945136">Specifies that output goes to the gsql client.</li><li id="EN-US_TOPIC_0000001233563247__l97d68fb85cc74ed7ba70c0a9a9e972c0">binary<p id="EN-US_TOPIC_0000001233563247__af01a29dc88e04328baf707347e43aea2"><a name="EN-US_TOPIC_0000001233563247__l97d68fb85cc74ed7ba70c0a9a9e972c0"></a><a name="l97d68fb85cc74ed7ba70c0a9a9e972c0"></a>Specifies that data is stored and read in binary mode instead of text mode. In binary mode, you cannot declare <strong id="EN-US_TOPIC_0000001233563247__b696233011251">DELIMITER</strong>, <strong id="EN-US_TOPIC_0000001233563247__b1696263019256">NULL</strong>, or <strong id="EN-US_TOPIC_0000001233563247__b59624301252">CSV</strong>. After specifying BINARY, CSV, FIXED and TEXT cannot be specified through <strong id="EN-US_TOPIC_0000001233563247__b842352706151632">option</strong> or <strong id="EN-US_TOPIC_0000001233563247__b842352706151637">copy_option</strong>.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l054c748aed754051b381d49b13156fd9">oid<p id="EN-US_TOPIC_0000001233563247__a308b76d03d224f8ba71c5ac8edf8960b"><a name="EN-US_TOPIC_0000001233563247__l054c748aed754051b381d49b13156fd9"></a><a name="l054c748aed754051b381d49b13156fd9"></a>Specifies the internal OID to be copied for each row.</p>
|
|
<div class="note" id="EN-US_TOPIC_0000001233563247__n959135cd53274798a323699f301b1f0b"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001233563247__a74282d55e111410a9df00b1f1a8bced4">An error is raised if OIDs are specified for a table that does not have OIDs, or in the case of copying a query.</p>
|
|
</div></div>
|
|
<p id="EN-US_TOPIC_0000001233563247__aba3e98b26d7f47f9a5520fa9383cd789">Valid value: <strong id="EN-US_TOPIC_0000001233563247__b842352706174916">true</strong>, <strong id="EN-US_TOPIC_0000001233563247__b84235270616240">on</strong>, <strong id="EN-US_TOPIC_0000001233563247__b8423527061633">false</strong>, and <strong id="EN-US_TOPIC_0000001233563247__b842352706174924">off</strong>.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__af17dfd8dcb304b92afcd55af061aebbe">Default value: <strong id="EN-US_TOPIC_0000001233563247__b026511148820">false/off</strong></p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l097437d990bb4c09899e8a217df69081">delimiter [ as ] 'character'<div class="p" id="EN-US_TOPIC_0000001233563247__aa201fb1da8cb4feca299b561fa90bed5"><a name="EN-US_TOPIC_0000001233563247__l097437d990bb4c09899e8a217df69081"></a><a name="l097437d990bb4c09899e8a217df69081"></a>Specifies the character that separates columns within each row (line) of the file.<div class="note" id="EN-US_TOPIC_0000001233563247__n9382163b0f854ef89fd37afe5f7f50fe"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001233563247__u1291500c6c7d4f3580f72529d260c7a3"><li id="EN-US_TOPIC_0000001233563247__l41e6678a1c2341c1afb6dea19723e24a">A delimiter cannot be <strong id="EN-US_TOPIC_0000001233563247__b3133142214014">\r</strong> or <strong id="EN-US_TOPIC_0000001233563247__b17383324184014">\n</strong>.</li><li id="EN-US_TOPIC_0000001233563247__lc81ded9591e94112b90c78baedfeeaba">A delimiter cannot be the same as the <strong id="EN-US_TOPIC_0000001233563247__b8423527061885">null</strong> value. The delimiter of CSV data cannot be same as the <strong id="EN-US_TOPIC_0000001233563247__b84235270618821">quote</strong> value.</li><li id="EN-US_TOPIC_0000001233563247__l61424f4fd6294c16998c5a5ece94b3e2">The delimiter of TEXT data cannot contain any of the following characters: \.abcdefghijklmnopqrstuvwxyz0123456789</li><li id="EN-US_TOPIC_0000001233563247__lda48c0747fa24cbeb8937cc973032dfc">The data length of a single row should be less than 1 GB. A row that has many columns using long delimiters cannot contain much valid data.</li><li id="EN-US_TOPIC_0000001233563247__lb72fc816213c4238a86c708385c98947">You are advised to use multi-characters and invisible characters for delimiters. For example, you can use the multiple-character delimiter "$^&" and invisible delimiters, such as E'\x07', E'\x08', and E'\x1b'.</li></ul>
|
|
</div></div>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001233563247__aea10c30a101f4001957d64ff30de8bcb">Value range: a multi-character delimiter within 10 bytes.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a985d1feb3c1647d3b691b565e54048b0">Default value:</p>
|
|
<ul id="EN-US_TOPIC_0000001233563247__u5fa702e9527f4263b6db4c0514b98cb1"><li id="EN-US_TOPIC_0000001233563247__l1ccc61053abe48aeaf0d3044d32218e9">A tab character in TEXT format</li><li id="EN-US_TOPIC_0000001233563247__le76241e1a9c94b199c7d006b8058f776">A comma (,) in CSV format</li><li id="EN-US_TOPIC_0000001233563247__l3baddb1b412947ccb8013f480ce721a1">No delimiter in FIXED format</li></ul>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l1ed3d3eef9a14f88a27ae8a8acdb4a2d">null [ as ] 'string'<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0117407672_p278830511508"><a name="EN-US_TOPIC_0000001233563247__l1ed3d3eef9a14f88a27ae8a8acdb4a2d"></a><a name="l1ed3d3eef9a14f88a27ae8a8acdb4a2d"></a>Specifies that a string represents a null value in a data file.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0117407672_p496208681508">Value range:</p>
|
|
<ul id="EN-US_TOPIC_0000001233563247__uf3d83f3ff58e4e29956c9e06d12fb8dd"><li id="EN-US_TOPIC_0000001233563247__lf012abfd6a2249be91870aee65674662">A null value cannot be <strong id="EN-US_TOPIC_0000001233563247__b33325154713">\r</strong> or <strong id="EN-US_TOPIC_0000001233563247__b2094118318476">\n</strong>. The maximum length is 100 characters.</li><li id="EN-US_TOPIC_0000001233563247__en-us_topic_0117407672_li19356921508">A null value cannot be the same as the <strong id="EN-US_TOPIC_0000001233563247__b2051613314812">delimiter</strong> or <strong id="EN-US_TOPIC_0000001233563247__b842352706181413">quote</strong> value.</li></ul>
|
|
<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0117407672_p174212321508">Default value:</p>
|
|
<ul id="EN-US_TOPIC_0000001233563247__u3a0293ac8e244fc6860cc324fb23c618"><li id="EN-US_TOPIC_0000001233563247__en-us_topic_0117407672_li18337011508">An empty string without quotation marks in CSV format</li><li id="EN-US_TOPIC_0000001233563247__ld71996186ab3477aab2900bb3f36086b"><strong id="EN-US_TOPIC_0000001233563247__b8423527061586">\N</strong> in TEXT format</li></ul>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l80dc3828aa254a1dbd55395d08639f5b">header<p id="EN-US_TOPIC_0000001233563247__af700de8d59014ffba8d806c35a91ee06"><a name="EN-US_TOPIC_0000001233563247__l80dc3828aa254a1dbd55395d08639f5b"></a><a name="l80dc3828aa254a1dbd55395d08639f5b"></a>Specifies whether a data file contains a table header. <strong id="EN-US_TOPIC_0000001233563247__b3229253205320">header</strong> is available only for CSV and FIXED files.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a702405200df946a49bb43bbc248f1218">In data import scenarios, if <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0058965600_b842352706145433_1">header</strong> is <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0058965600_b842352706101629_1">on</strong>, the first row of the data file will be identified as the header and ignored. If <strong id="EN-US_TOPIC_0000001233563247__b8471932145517">header</strong> is <strong id="EN-US_TOPIC_0000001233563247__b842352706164837">off</strong>, the first row will be identified as a data row.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__p2434321996">If header is <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0058965600_b842352706162255_1">on</strong>, <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0058965600_b84235270616233_1">fileheader</strong> must be specified. <strong id="EN-US_TOPIC_0000001233563247__b1652551318356">fileheader</strong> specifies the content in the header. If header is <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0058965600_b842352706152947">off</strong>, the exported file does not contain a header.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0117407672_p683775815511">Valid value: <strong id="EN-US_TOPIC_0000001233563247__b9489524214">true</strong>, <strong id="EN-US_TOPIC_0000001233563247__b14489112923">on</strong>, <strong id="EN-US_TOPIC_0000001233563247__b64897217214">false</strong>, and <strong id="EN-US_TOPIC_0000001233563247__b34891210213">off</strong>.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a3f0ce65cda0145dcb1aeaa6101ed5893">Default value: <strong id="EN-US_TOPIC_0000001233563247__b943920686">false/off</strong></p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__ld93f8ab5dff3434995cfcc966f3095f6">quote [ as ] 'character'<p id="EN-US_TOPIC_0000001233563247__a56b0f415ef6141298be953b62bc97b4c"><a name="EN-US_TOPIC_0000001233563247__ld93f8ab5dff3434995cfcc966f3095f6"></a><a name="ld93f8ab5dff3434995cfcc966f3095f6"></a>Specifies the quote character used when a data value is referenced in a CSV file.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a924cd97d8ea14f76b4408fd29f84d25d">Default value: double quotation mark ("").</p>
|
|
<div class="note" id="EN-US_TOPIC_0000001233563247__n2951854f2b624a228f5c7c00121dfd1e"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001233563247__ua69c466df5cb4fa2ae284fb32a553476"><li id="EN-US_TOPIC_0000001233563247__l4397da68db4542cba793a6d03efd4e86">The <strong id="EN-US_TOPIC_0000001233563247__b357112920415">quote</strong> value cannot be the same as the <strong id="EN-US_TOPIC_0000001233563247__b084413414417">delimiter</strong> or <strong id="EN-US_TOPIC_0000001233563247__b765618437418">null</strong> value.</li><li id="EN-US_TOPIC_0000001233563247__l7d009353d4544f11b8db0d0386fd269b">The <strong id="EN-US_TOPIC_0000001233563247__b84235270614567">quote</strong> value must be a single-byte character.</li><li id="EN-US_TOPIC_0000001233563247__l72c7110da938497bb9d2fabd23e85f87">You are advised to use invisible characters as quotes, for example, E'\x07', E'\x08', and E'\x1b'.</li></ul>
|
|
</div></div>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l873c0fb4956a45c78bc147885052e206">escape [ as ] 'character'<p id="EN-US_TOPIC_0000001233563247__a2a79e4c702694e3da5f751d251e09600"><a name="EN-US_TOPIC_0000001233563247__l873c0fb4956a45c78bc147885052e206"></a><a name="l873c0fb4956a45c78bc147885052e206"></a>This option is allowed only when using CSV format. This must be a single one-byte character.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__ab2b46e6b6a674a4794b3d69526b99e25">Default value: double quotation mark (""). If the value is the same as the <strong id="EN-US_TOPIC_0000001233563247__b842352706145917">quote</strong> value, it will be replaced with <strong id="EN-US_TOPIC_0000001233563247__b842352706145950">\0</strong>.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l290a3c520ab14602a5711ac9e13c7f0e">force quote column_list | *<p id="EN-US_TOPIC_0000001233563247__p102471053171717"><a name="EN-US_TOPIC_0000001233563247__l290a3c520ab14602a5711ac9e13c7f0e"></a><a name="l290a3c520ab14602a5711ac9e13c7f0e"></a>Quotes all not-null values in each declared column when <strong id="EN-US_TOPIC_0000001233563247__b10818145141119">CSV COPY TO</strong> is used. NULL values will not be quoted.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a3dac5a581d5c447da97d3e13f06ce5c7">Value range: an existing column.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__l71b135cad25d44448a8adae09999cef3">force not null column_list<p id="EN-US_TOPIC_0000001233563247__aff1b90c843ff44d2b6c62d014e37e339"><a name="EN-US_TOPIC_0000001233563247__l71b135cad25d44448a8adae09999cef3"></a><a name="l71b135cad25d44448a8adae09999cef3"></a>In CSV COPY FROM mode, processes each specified column as though it were quoted and hence not a null value.</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__a2cffecc6bc4544fd9841e28441d80c6d">Value range: an existing column.</p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001233563247__sb77d0d48a8f14b6a8ed23980a4d26094"><h4 class="sectiontitle">Examples</h4><div class="p" id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_p189452022124618">Create the target table <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b6511366198">copy_example</strong>.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_screen8149131124510"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span>
|
|
<span class="normal">4</span>
|
|
<span class="normal">5</span>
|
|
<span class="normal">6</span>
|
|
<span class="normal">7</span>
|
|
<span class="normal">8</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">create</span><span class="w"> </span><span class="k">table</span><span class="w"> </span><span class="n">copy_example</span>
|
|
<span class="p">(</span>
|
|
<span class="w"> </span><span class="n">col_1</span><span class="w"> </span><span class="nb">integer</span><span class="p">,</span>
|
|
<span class="w"> </span><span class="n">col_2</span><span class="w"> </span><span class="nb">text</span><span class="p">,</span>
|
|
<span class="w"> </span><span class="n">col_3</span><span class="w"> </span><span class="nb">varchar</span><span class="p">(</span><span class="mi">12</span><span class="p">),</span>
|
|
<span class="w"> </span><span class="n">col_4</span><span class="w"> </span><span class="nb">date</span><span class="p">,</span>
|
|
<span class="w"> </span><span class="n">col_5</span><span class="w"> </span><span class="k">time</span>
|
|
<span class="p">);</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
<ul id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_ul1958973904816"><li id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_li1858916392486">Example 1: Copy data from stdin to the target table <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b750612231198">copy_example</strong>.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_se007bfdc102a4cb58c6054cae97de60f"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="err">\</span><span class="k">copy</span><span class="w"> </span><span class="n">copy_example</span><span class="w"> </span><span class="k">from</span><span class="w"> </span><span class="k">stdin</span><span class="w"> </span><span class="n">csv</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<div class="p" id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_p15203346204816">When the <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b4393530101914">>></strong> characters are displayed, enter data. Enter a backslash and a period (\.) to end your input.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_sbe2d24e755bd4532b77a3a144100c41a"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span>
|
|
<span class="normal">4</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">Enter</span><span class="w"> </span><span class="k">data</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="n">be</span><span class="w"> </span><span class="n">copied</span><span class="w"> </span><span class="n">followed</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">newline</span><span class="p">.</span>
|
|
<span class="k">End</span><span class="w"> </span><span class="k">with</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">backslash</span><span class="w"> </span><span class="k">and</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="k">period</span><span class="w"> </span><span class="k">on</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">line</span><span class="w"> </span><span class="k">by</span><span class="w"> </span><span class="n">itself</span><span class="p">.</span>
|
|
<span class="o">>></span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="ss">"iamtext"</span><span class="p">,</span><span class="ss">"iamvarchar"</span><span class="p">,</span><span class="mi">2006</span><span class="o">-</span><span class="mi">07</span><span class="o">-</span><span class="mi">07</span><span class="p">,</span><span class="mi">12</span><span class="p">:</span><span class="mi">00</span><span class="p">:</span><span class="mi">00</span>
|
|
<span class="o">>></span><span class="w"> </span><span class="err">\</span><span class="p">.</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_li1258044212534">Example 2: The <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b1078210444204">example.csv</strong> file is in the local directory <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b9365355142013">/local/data/</strong> and the file contains the header line. (|) is used as the delimiter, and the double quotation marks are used for <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b13141942132315">quote</strong>. The content is as follows:<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_p729116478537">iamheader</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_p7143149185318">1|"iamtext"|"iamvarchar"|2006-07-07|12:00:00</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_p584795010538">2|"iamtext"|"iamvarchar"|2022-07-07|19:00:02</p>
|
|
<div class="p" id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_p354215529531">Import data from the local file <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b1620285810243">example.csv</strong> to the target table <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b1677410542515">copy_example</strong>. If the header option is <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b845282543112">on</strong>, the first row is automatically ignored. By default, quotation marks are used for <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b1937114115242">quote</strong>.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_screen693416277535"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="err">\</span><span class="k">copy</span><span class="w"> </span><span class="n">copy_example</span><span class="w"> </span><span class="k">from</span><span class="w"> </span><span class="s1">'/local/data/example.csv'</span><span class="w"> </span><span class="k">with</span><span class="p">(</span><span class="n">header</span><span class="w"> </span><span class="s1">'on'</span><span class="p">,</span><span class="w"> </span><span class="n">format</span><span class="w"> </span><span class="s1">'csv'</span><span class="p">,</span><span class="w"> </span><span class="k">delimiter</span><span class="w"> </span><span class="s1">'|'</span><span class="p">,</span><span class="w"> </span><span class="n">date_format</span><span class="w"> </span><span class="s1">'yyyy-mm-dd'</span><span class="p">,</span><span class="w"> </span><span class="n">time_format</span><span class="w"> </span><span class="s1">'hh24:mi:ss'</span><span class="p">);</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_li91171589547">Example 3: The <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b758410203817">example.csv</strong> file is in the local directory <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b1128111112383">/local/data/</strong>. The comma (,) is used as the delimiter, and the quotation mark (") is used for <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b118611343143810">quote</strong>. The last field is missing in the first line, and one more field is added in the second line. The content is as follows:<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_p1098837115412">1,"iamtext","iamvarchar",2006-07-07</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_p298133719543">2,"iamtext","iamvarchar",2022-07-07,19:00:02,12:00:00</p>
|
|
<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_p498837155415">Import data from the local file <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b368441733919">example.csv</strong> to the target table <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b1243883219396">copy_example</strong>. The default delimiter is (,). Therefore, you do not need to specify the delimiter. Because the fault tolerance parameters <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b1789032154019">IGNORE_EXTRA_DATA</strong> and <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b9795637174015">FILL_MISSING_FIELD</strong> are specified, the missing fields will be replaced with <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b1751345114018">NULL</strong>, the extra fields are ignored.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_screen6733182265515"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="err">\</span><span class="k">copy</span><span class="w"> </span><span class="n">copy_example</span><span class="w"> </span><span class="k">from</span><span class="w"> </span><span class="s1">'/local/data/example.csv'</span><span class="w"> </span><span class="k">with</span><span class="p">(</span><span class="w"> </span><span class="n">format</span><span class="w"> </span><span class="s1">'csv'</span><span class="p">,</span><span class="w"> </span><span class="n">date_format</span><span class="w"> </span><span class="s1">'yyyy-mm-dd'</span><span class="p">,</span><span class="w"> </span><span class="n">time_format</span><span class="w"> </span><span class="s1">'hh24:mi:ss'</span><span class="p">,</span><span class="w"> </span><span class="n">IGNORE_EXTRA_DATA</span><span class="w"> </span><span class="s1">'true'</span><span class="p">,</span><span class="w"> </span><span class="n">FILL_MISSING_FIELD</span><span class="w"> </span><span class="s1">'true'</span><span class="p">);</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_li5530132813555">Example 4: Export the content of the <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b1572118664120">copy_example</strong> table to stdout in CSV format, use double quotation marks as for <strong id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_b999542674117">quote</strong>, and use quotes to enclose the fourth and fifth columns.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_screen9536123735617"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="err">\</span><span class="k">copy</span><span class="w"> </span><span class="n">copy_example</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="k">stdout</span><span class="w"> </span><span class="n">CSV</span><span class="w"> </span><span class="n">quote</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="s1">'"'</span><span class="w"> </span><span class="k">force</span><span class="w"> </span><span class="n">quote</span><span class="w"> </span><span class="n">col_4</span><span class="p">,</span><span class="n">col_5</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</li></ul>
|
|
<p id="EN-US_TOPIC_0000001233563247__en-us_topic_0000001099134686_p1727382520485"></p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0179.html">Importing Data</a></div>
|
|
</div>
|
|
</div>
|
|
|