Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pg_dump -t: give WHERE condition

6,751 views
Skip to first unread message

Thomas Guettler

unread,
Dec 3, 2007, 9:36:28 AM12/3/07
to
Hi,

I want to dump some rows of a table. I couldn't find a way to
give pg_dump a where condition.

How can you dump (for restore) with a where-condition?

Thomas

Laurenz Albe

unread,
Dec 3, 2007, 10:00:53 AM12/3/07
to

You cannot specify a where clause for pg_dump.

You can use COPY (or \copy in psql) to dump the results of an
arbitrary SQL query to a file.

Use COPY (or \copy) to restore the result to another table.

Yours,
Laurenz Albe

Toby A Inkster

unread,
Dec 3, 2007, 12:49:38 PM12/3/07
to
Laurenz Albe wrote:

> You can use COPY (or \copy in psql) to dump the results of an arbitrary
> SQL query to a file.

Personally, I'd...

$ psql mydb
> CREATE TABLE temp1 (LIKE mytable);
> INSERT INTO temp1 SELECT * FROM mytable WHERE myconditions;
> \q
$ pg_dump --data-only --column-inserts -t temp1 mtdb >out.sql
$ psql mydb
> DROP TABLE temp1;
> \q

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 9 days, 27 min.]

Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/

Thomas Guettler

unread,
Dec 4, 2007, 11:06:38 AM12/4/07
to
Thank you Toby and Laurenz for your solutions.

Toby A Inkster schrieb:

0 new messages