Skip to content

Instantly share code, notes, and snippets.

@jahrmando
Last active July 5, 2021 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahrmando/612f0b5ce8cc74af281bd5ae8b2be590 to your computer and use it in GitHub Desktop.
Save jahrmando/612f0b5ce8cc74af281bd5ae8b2be590 to your computer and use it in GitHub Desktop.
Extract a limit records from a table and restore it on postgresql

Extract a limit records from a table and restore it on postgresql

  1. Create a temp table
SELECT p.*
    INTO TABLE tmp_my_table
from my_table p
  1. Dump the table
pg_dump my_database --table tmp_my_table | sed 's/public.tmp_/public./' > tmp_my_table.sql
  1. Restore the table data on the original table (my_table)
psql -d my_database -U user < tmp_my_table.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment