Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.