Export/import subset of data from table in Postgres


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.