-
pg_dump -t: give WHERE condition
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
-
Re: pg_dump -t: give WHERE condition
Thomas Guettler wrote:
> 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?
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
-
Re: pg_dump -t: give WHERE condition
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/1...tunes-sharing/
-
Re: pg_dump -t: give WHERE condition
Thank you Toby and Laurenz for your solutions.
Toby A Inkster schrieb:
> 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
>