Re: copy/dump database to text/csv files

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: copy/dump database to text/csv files
Date: 2014-07-24 19:23:22
Message-ID: lqrmfe$62c$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

William Nolf wrote on 24.07.2014 21:04:
> This is probably an easy one for most sql users but I don't use it
> very often.
>
> We have a postgres database that was used for an application we no
> longer use. However, we would
>
> like to copy/dump the tables to files, text or csv so we can post
> them to sharepoint.
>
> Copy seems to be what I want. But it only does one table at a time.
> There is 204 tables with a schemaname=public. I need to be copy the
> tables with data to files. I need something like a for
>
> loop which checks if the table is populated if so, copy it to
> tablename.csv file
>
> Any ideas?

If you are not constrained to psql you might want to have a look at my tool SQL Workbench/J (http://www.sql-workbench.net/) which contains an export command to do just that: export all tables of a schema (or multiple schemas) in a defined format, see here: http://www.sql-workbench.net/manual/command-export.html

Using that, this would be as easy as:

WbExport -outputDir=/some/export/directory
-type=text
-header=true
-delimiter=','
-sourceTable=public.*;

You also have more control over the format of the exported data than you would have with psql I dare say.

Disclosure: I am the author of that tool.

Regards
Thomas

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Krystian Bigaj 2014-07-24 19:36:24 Re: System shutdown signal on Windows (was Re: )
Previous Message John R Pierce 2014-07-24 19:13:56 Re: copy/dump database to text/csv files