Skip to content

Instantly share code, notes, and snippets.

@raprasad
Created June 1, 2017 13:14
Show Gist options
  • Save raprasad/e9ceb64bde413fa1dffe42aca8ab73ea to your computer and use it in GitHub Desktop.
Save raprasad/e9ceb64bde413fa1dffe42aca8ab73ea to your computer and use it in GitHub Desktop.
postgres copy table from 1 db to another

Copy from source table: dvn_thedata -> authenticateduser

  • Go to the psql shell: psql dvn_thedata
  • Copy to a text file:
\copy (select id, affiliation, email, firstname, lastname, modificationtime, position, superuser, useridentifier from authenticateduser order by id) to '/tmp/auth_user.csv' CSV HEADER

Load to the target table: dvndb -> authenticateduser

  • Modify the csv if needed--e.g. if don't want to overwrite existing rows
  • Go to the psql shell: psql dvndb
  • Load the text file
copy authenticateduser(id, affiliation, email, firstname, lastname, modificationtime, position, superuser, useridentifier) 
FROM '/tmp/auth_user.csv' DELIMITER ',' CSV HEADER;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment