Using pg_dump only to get insert statements from one table in the database

I am looking for a way to get all rows as INSERT from one specific table in a database using pg_dump in PostgreSQL.

For example, I have table A and all the rows in table A. I need to, as an INSERT , it also needs to unload these instructions into a file.

Is it possible?

+66
postgresql
May 18 '10 at 14:08
source share
2 answers

if version <8.4.0

 pg_dump -D -t <table> <database> 

Add -a before -t if you only want to INSERT, without CREATE TABLE, etc., to set up the table first.

version> = 8.4.0

 pg_dump --column-inserts --data-only --table=<table> <database> 
+129
May 18 '10 at 2:14
source share

If you want to dump your insertions into the .sql file:

  • cd to the location where you want to find the .sql file
  • pg_dump --column-inserts --data-only --table=<table> <database> > my_dump.sql

Pay attention to the command > my_dump.sql . This will put everything in a sql file called my_dump

+8
Jan 20 '17 at 1:51 on
source share



All Articles