<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: How to export table data to file / csv &#8211; PostgreSQL</title>
	<atom:link href="http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/</link>
	<description>Thoughts on Java, Maven, Hibernate, Spring , Ajax web development</description>
	<lastBuildDate>Thu, 11 Mar 2010 18:41:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: virender</title>
		<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/comment-page-1/#comment-5552</link>
		<dc:creator>virender</dc:creator>
		<pubDate>Thu, 11 Feb 2010 10:07:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.mkyong.com/?p=188#comment-5552</guid>
		<description>Hi mkyong,

I think also need to \o after completion....</description>
		<content:encoded><![CDATA[<p>Hi mkyong,</p>
<p>I think also need to \o after completion&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mkyong</title>
		<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/comment-page-1/#comment-1842</link>
		<dc:creator>mkyong</dc:creator>
		<pubDate>Tue, 30 Jun 2009 14:24:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.mkyong.com/?p=188#comment-1842</guid>
		<description>Thanks for your tips</description>
		<content:encoded><![CDATA[<p>Thanks for your tips</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Annoyed Programmed</title>
		<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/comment-page-1/#comment-1841</link>
		<dc:creator>Annoyed Programmed</dc:creator>
		<pubDate>Tue, 30 Jun 2009 14:20:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.mkyong.com/?p=188#comment-1841</guid>
		<description>Oops looks like someone else already suggested copy.

I wish they had mentioned that it would handle the escaping cleanly.</description>
		<content:encoded><![CDATA[<p>Oops looks like someone else already suggested copy.</p>
<p>I wish they had mentioned that it would handle the escaping cleanly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Annoyed Programmed</title>
		<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/comment-page-1/#comment-1840</link>
		<dc:creator>Annoyed Programmed</dc:creator>
		<pubDate>Tue, 30 Jun 2009 14:18:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.mkyong.com/?p=188#comment-1840</guid>
		<description>OK.  I finally figured out the right way to do this.

Basically you need to use the COPY command.  I.e.

COPY (SQL_QUERY) TO FILE_NAME WITH CSV HEADER

e.g.

psql -p 5433 -U dba dbname -c “COPY (select url from urltable where scoreid=1 limit 25000) TO STDOUT WITH CSV HEADER;” &gt; /home/yongmo/data25000.csv

I&#039;m glad this there&#039;s a way to do this but I wish it was better documented.</description>
		<content:encoded><![CDATA[<p>OK.  I finally figured out the right way to do this.</p>
<p>Basically you need to use the COPY command.  I.e.</p>
<p>COPY (SQL_QUERY) TO FILE_NAME WITH CSV HEADER</p>
<p>e.g.</p>
<p>psql -p 5433 -U dba dbname -c “COPY (select url from urltable where scoreid=1 limit 25000) TO STDOUT WITH CSV HEADER;” &gt; /home/yongmo/data25000.csv</p>
<p>I&#8217;m glad this there&#8217;s a way to do this but I wish it was better documented.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mkyong</title>
		<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/comment-page-1/#comment-1837</link>
		<dc:creator>mkyong</dc:creator>
		<pubDate>Tue, 30 Jun 2009 05:23:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.mkyong.com/?p=188#comment-1837</guid>
		<description>Hi , thanks for your comment, i didn&#039;t know about it. Ya it may not work in your case (escaping) , however it work fine in most of the case, usually data wont care about escape right?</description>
		<content:encoded><![CDATA[<p>Hi , thanks for your comment, i didn&#8217;t know about it. Ya it may not work in your case (escaping) , however it work fine in most of the case, usually data wont care about escape right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Annoyed Programmed</title>
		<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/comment-page-1/#comment-1835</link>
		<dc:creator>Annoyed Programmed</dc:creator>
		<pubDate>Mon, 29 Jun 2009 21:43:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.mkyong.com/?p=188#comment-1835</guid>
		<description>PLEASE DON&#039;T TRY THIS.

THIS DOESN&#039;T DO ANY ESCAPING.

If your data contains comments in field data your files will break.  Data with embedded new lines will be even worst.

Postgresql needs a real export to CSV for select statements.  Unfortunately in does have this functionality.</description>
		<content:encoded><![CDATA[<p>PLEASE DON&#8217;T TRY THIS.</p>
<p>THIS DOESN&#8217;T DO ANY ESCAPING.</p>
<p>If your data contains comments in field data your files will break.  Data with embedded new lines will be even worst.</p>
<p>Postgresql needs a real export to CSV for select statements.  Unfortunately in does have this functionality.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mkyong</title>
		<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/comment-page-1/#comment-1711</link>
		<dc:creator>mkyong</dc:creator>
		<pubDate>Tue, 19 May 2009 13:55:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.mkyong.com/?p=188#comment-1711</guid>
		<description>hi ressu, 

   Thanks for tips ~</description>
		<content:encoded><![CDATA[<p>hi ressu, </p>
<p>   Thanks for tips ~</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ressu</title>
		<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/comment-page-1/#comment-1710</link>
		<dc:creator>ressu</dc:creator>
		<pubDate>Tue, 19 May 2009 10:01:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.mkyong.com/?p=188#comment-1710</guid>
		<description>Why not use \copy

\copy (select url from urltable where scoreid=1 limit 25000) TO &#039;/tmp/filename.csv&#039; CSV

\copy command can do various other tricks aswell.</description>
		<content:encoded><![CDATA[<p>Why not use \copy</p>
<p>\copy (select url from urltable where scoreid=1 limit 25000) TO &#8216;/tmp/filename.csv&#8217; CSV</p>
<p>\copy command can do various other tricks aswell.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mkyong</title>
		<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/comment-page-1/#comment-1599</link>
		<dc:creator>mkyong</dc:creator>
		<pubDate>Sun, 26 Apr 2009 16:06:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.mkyong.com/?p=188#comment-1599</guid>
		<description>Hi No, 

   Is /c:/no a folder? Just type &quot;\o /c:/no/dummy.csv&quot;

Hope help</description>
		<content:encoded><![CDATA[<p>Hi No, </p>
<p>   Is /c:/no a folder? Just type &#8220;\o /c:/no/dummy.csv&#8221;</p>
<p>Hope help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: No</title>
		<link>http://www.mkyong.com/database/how-to-export-table-data-to-file-csv-postgresql/comment-page-1/#comment-1576</link>
		<dc:creator>No</dc:creator>
		<pubDate>Thu, 23 Apr 2009 08:21:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.mkyong.com/?p=188#comment-1576</guid>
		<description>Thank.

if i want to save in my computer in /c:/no file can you rewrite command for me please

Many Thank.</description>
		<content:encoded><![CDATA[<p>Thank.</p>
<p>if i want to save in my computer in /c:/no file can you rewrite command for me please</p>
<p>Many Thank.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
