What's the best way to copy a subset of a table's rows from one database to another in Postgres?

后端 未结 4 1436
我在风中等你
我在风中等你 2021-02-04 17:52

I\'ve got a production DB with, say, ten million rows. I\'d like to extract the 10,000 or so rows from the past hour off of production and copy them to my local box. How do I do

4条回答
  •  感动是毒
    2021-02-04 18:02

    source server:

    BEGIN;
    
    CREATE TEMP TABLE mmm_your_table_here AS
        SELECT * FROM your_table_here WHERE your_condition_here;
    
    COPY mmm_your_table_here TO 'u:\\source.copy';
    
    ROLLBACK;
    

    your local box:

    -- your_destination_table_here must be created first on your box
    
    COPY your_destination_table_here FROM 'u:\\source.copy';
    

    article: http://www.postgresql.org/docs/8.1/static/sql-copy.html

提交回复
热议问题