Search code examples
sqldatabasepostgresqlsql-insertpg-dump

Using `pg_dump` to only get insert statements from one table within database


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

E.g., I have table A and all rows in table A I need as INSERT statements, it should also dump those statements to a file.

Is this possible?


Solution

  • if version < 8.4.0

    pg_dump -D -t <table> <database>
    

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

    version >= 8.4.0

    pg_dump --column-inserts --data-only --table=<table> <database>