<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>COPY FROM &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/copy-from/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Fri, 15 Sep 2017 07:49:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>Import or Export a CSV File using PostgreSQL COPY Command</title>
		<link>https://www.dbrnd.com/2015/09/import-or-export-a-csv-file-using-postgresql-copy-command/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 20 Sep 2015 17:45:59 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[COPY FROM]]></category>
		<category><![CDATA[COPY TO]]></category>
		<category><![CDATA[CSV File]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=673</guid>

					<description><![CDATA[In this post, I am sharing a demonstration on how to export or import CSV data using the PostgreSQL COPY command. The CSV files are most famous for the necessary data migration activities. Database developer does not need to write or create any particular database link between two servers. They can easily import data in [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fimport-or-export-a-csv-file-using-postgresql-copy-command%2F&amp;linkname=Import%20or%20Export%20a%20CSV%20File%20using%20PostgreSQL%20COPY%20Command" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fimport-or-export-a-csv-file-using-postgresql-copy-command%2F&amp;linkname=Import%20or%20Export%20a%20CSV%20File%20using%20PostgreSQL%20COPY%20Command" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fimport-or-export-a-csv-file-using-postgresql-copy-command%2F&amp;linkname=Import%20or%20Export%20a%20CSV%20File%20using%20PostgreSQL%20COPY%20Command" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fimport-or-export-a-csv-file-using-postgresql-copy-command%2F&amp;linkname=Import%20or%20Export%20a%20CSV%20File%20using%20PostgreSQL%20COPY%20Command" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fimport-or-export-a-csv-file-using-postgresql-copy-command%2F&amp;linkname=Import%20or%20Export%20a%20CSV%20File%20using%20PostgreSQL%20COPY%20Command" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fimport-or-export-a-csv-file-using-postgresql-copy-command%2F&amp;linkname=Import%20or%20Export%20a%20CSV%20File%20using%20PostgreSQL%20COPY%20Command" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fimport-or-export-a-csv-file-using-postgresql-copy-command%2F&#038;title=Import%20or%20Export%20a%20CSV%20File%20using%20PostgreSQL%20COPY%20Command" data-a2a-url="https://www.dbrnd.com/2015/09/import-or-export-a-csv-file-using-postgresql-copy-command/" data-a2a-title="Import or Export a CSV File using PostgreSQL COPY Command"></a></p><p>In this post, I am sharing a demonstration on how to export or import CSV data using the PostgreSQL COPY command.</p>
<blockquote><p>The CSV files are most famous for the necessary data migration activities. Database developer does not need to write or create any particular database link between two servers.</p>
<p>They can easily import data in CSV and export that CSV into another server and also CSV file does not have any data length limitation like any other XLS file. </p>
<p>User can store millions of records into CSV file.</p></blockquote>
<p>This technique is preferred only for temporary purposes, and if it continues the process, the user has to write some automated process like database server replication.</p>
<p>PostgreSQL provides the COPY command to import or export CSV data into the PostgreSQL table.</p>
<p>Let me demonstrate this:</p>
<p>First, I create one table and import data from CSV file. I have already created a CSV file with sample data. Make sure that, your table column and CSV column would be same.</p>
<p>You can create this CSV file using a comma delimited save as option of Microsoft excel.</p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2015/09/PostgresCSV.png"><img fetchpriority="high" decoding="async" class="alignnone wp-image-683 size-full" title="Postgres CSV" src="https://www.dbrnd.com/wp-content/uploads/2015/09/PostgresCSV.png" alt="Postgres CSV" width="565" height="493" srcset="https://www.dbrnd.com/wp-content/uploads/2015/09/PostgresCSV.png 565w, https://www.dbrnd.com/wp-content/uploads/2015/09/PostgresCSV-300x262.png 300w, https://www.dbrnd.com/wp-content/uploads/2015/09/PostgresCSV-150x131.png 150w" sizes="(max-width: 565px) 100vw, 565px" /></a></p><pre class="crayon-plain-tag">CREATE TABLE tbl_testcsv
(
  rno integer,
  name character varying
);</pre><p>
<p><strong>Now COPY the data from CSV file into the table:</strong></p><pre class="crayon-plain-tag">COPY tbl_testcsv FROM 'E:\dbrnd.com\Postwork\testcsv.csv'
WITH DELIMITER ','
CSV HEADER;</pre><p>
<p><strong>After executing of COPY command, you can check the result:</strong></p><pre class="crayon-plain-tag">SELECT *FROM tbl_testcsv;</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2015/09/CSVTablelData.png"><img decoding="async" class="alignnone wp-image-685 size-full" title="Postgres CSV Tablel Data" src="https://www.dbrnd.com/wp-content/uploads/2015/09/CSVTablelData.png" alt="Postgres CSV Tablel Data" width="230" height="226" srcset="https://www.dbrnd.com/wp-content/uploads/2015/09/CSVTablelData.png 230w, https://www.dbrnd.com/wp-content/uploads/2015/09/CSVTablelData-150x147.png 150w" sizes="(max-width: 230px) 100vw, 230px" /></a></p>
<p><strong>Add some more records in Table and then we export the data into CSV file:</strong></p><pre class="crayon-plain-tag">INSERT INTO tbl_testcsv
VALUES 
(9,'YRQ'),(10,'QWE')
,(11,'MNB'),(12,'FGH');</pre><p>
<p><strong>Now, export this data using the COPY command:</strong></p><pre class="crayon-plain-tag">COPY tbl_testcsv TO 'E:\dbrnd.com\Postwork\testcsv.csv'
WITH DELIMITER ','
CSV HEADER;
--Query returned successfully: 12 rows affected,</pre><p>
<p><strong>Now, check your CSV file. You can find newly inserted data:</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2015/09/CSVExcelData.png"><img decoding="async" class="alignnone wp-image-687 size-full" title="Postgres CSV Excel Data" src="https://www.dbrnd.com/wp-content/uploads/2015/09/CSVExcelData.png" alt="" width="198" height="336" srcset="https://www.dbrnd.com/wp-content/uploads/2015/09/CSVExcelData.png 198w, https://www.dbrnd.com/wp-content/uploads/2015/09/CSVExcelData-177x300.png 177w, https://www.dbrnd.com/wp-content/uploads/2015/09/CSVExcelData-150x255.png 150w" sizes="(max-width: 198px) 100vw, 198px" /></a></p>
<p><strong>You can also define a particular column or write a full select statement in the COPY command:</strong><br />
Below is a sample script.</p><pre class="crayon-plain-tag">COPY tbl_testcsv(rno)
TO 'E:\dbrnd.com\Postwork\testcsv.csv'
WITH DELIMITER ','
CSV HEADER;</pre><p>
</p><pre class="crayon-plain-tag">COPY (SELECT rno,name FROM tbl_testcsv WHERE rno=8)
TO 'E:\dbrnd.com\Postwork\testcsv.csv'
WITH DELIMITER ','
CSV HEADER;</pre><p>
<p>This is a full detailed example of Postgres COPY command, please test this sample and let me know for further assistance.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
