Take the 2-minute tour ×

I have a PostgreSQL database with a multi-Gb table (which contains a log of certain events). I need to pass the latest events to an analyst - let's say he only needs events from the last month.

How can I produce a dump of only those rows that have, say, created_at > '2012-05-01'?

share|improve this question
add comment

2 Answers

Another way is to use COPY or \copy (the psql command), something like:

COPY (SELECT * FROM big_table WHERE created_at > '2012-05-01') TO '/path/to/a/dump/file';
share|improve this answer
But does it produce actual INSERT statements? More generally speaking, how do you get the dump back into the database? –  Leonid Shevtsov May 28 '12 at 13:13
No, it doesn't produce valid SQL statments - its output is CSV, "text" or binary format. But it could be imported in another DB using the same commands. –  Milen A. Radev May 28 '12 at 13:34
add comment

Your Answer


