Posted By

jturmel on 08/06/10


Tagged

table data import export postgres


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

chrisvaughn


Export/import subset of data from table in Postgres


 / Published in: Bash
 

  1. # Development Server
  2.  
  3. psql database_name
  4. CREATE TABLE temp_table_name AS SELECT * FROM actual_table WHERE some_field = 'some_value' ORDER BY some_field;
  5. \q
  6.  
  7. pg_dump -t temp_table_name database_name | gzip > temp_table_name.sql.gz
  8. scp temp_table_name.sql.gz user@server:
  9. psql database_name
  10. DROP TABLE temp_table_name;
  11.  
  12. # Production Server
  13.  
  14. zcat temp_table_name.sql.gz | psql database_name
  15. psql database_name
  16. INSERT INTO actual_table SELECT * FROM temp_table_name;
  17. DROP TABLE temp_table_name;

Report this snippet  

You need to login to post a comment.