3

I want to import data just for particular tables in Postgres. How can I do that?

I've tried the following command. Didnt worked though.

pg_dump -U postgres -a -d -t data_pptlconfig db_name  > db_file
3
  • Import to postgres or export from postgres ? Commented Apr 6, 2014 at 17:14
  • pg_dump is intended for export (backups). Also, the > db_file can only write to the db_file, it cannot read from it. Commented Apr 6, 2014 at 17:38
  • Assuming you mean "a dump" when you say a "postgres file" ... what format is the dump? If it's an SQL format dump, you'd have to extract the part you want with a text editor. If it's a custom-format dump, you can use pg_restore with the -t flag. Use file the-dump-file to find out which it is if you do not know. Commented Apr 7, 2014 at 2:41

1 Answer 1

2

Assuming you mean "a dump" when you say a "postgres file":

If it's an SQL format dump, you'd have to extract the part you want with a text editor and run just that part. The dump is essentially an SQL "program" to re-create the database, so there's really no other way to selectively restore bits of it.

If it's a custom-format dump, you can use pg_restore with the -t flag.

Use file the-dump-file to find out which it is if you do not know. Or look at the file with a text editor - if the first five bytes are PGDMP it's a PostgreSQL custom format dump; otherwise it'll be an SQL format dump.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.