dumping table contents in a sensible order - Mailing list pgsql-general

From Chris Withers
Subject dumping table contents in a sensible order
Date
Msg-id 1529acd7-8454-959b-5199-dd92eb774504@simplistix.co.uk
Whole thread Raw
Responses Re: dumping table contents in a sensible order  (Jerry Sievers <gsievers19@comcast.net>)
Re: dumping table contents in a sensible order  ("btober@computer.org" <btober@broadstripe.net>)
Re: dumping table contents in a sensible order  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
Hi All,

I have a database that I want to dump three tables from, for use in
development. They form a subset of the data, so I was dumping like this:

pg_dump thedatabase --inserts -t table_one -t depends_on_table_one -t
depends_on_previous_two > dump.sql

However, when I try to load this using the following:

psql thedatabase_dev < dump.sql

I get the following:

SET
ERROR:  unrecognized configuration parameter "lock_timeout"
SET
SET
SET
SET
ERROR:  unrecognized configuration parameter "row_security"
SET
SET
SET
ERROR:  relation "table_one" already exists
ALTER TABLE
ERROR:  relation "depends_on_previous_two" already exists
ALTER TABLE
ERROR:  relation "depends_on_previous_two_id_seq" already exists
ALTER TABLE
ALTER SEQUENCE
ALTER TABLE
INSERT 0 1
...
INSERT 0 1
ERROR:  insert or update on table "table_one" violates foreign key
constraint "table_one_parent_id_fkey"
DETAIL:  Key (parent_id)=(xxx) is not present in table "table_one".

So, the problem appears to be that table_one is self-referential by way
of a parent_id field.

How can I either:

- dump the table in an insertable order?
- have the load only apply the foreign key constraint at the end of each
table import?

cheers,

Chris


pgsql-general by date:

Previous
From: Rich Shepard
Date:
Subject: Upgrade from 9.5.4 to 9.6.1
Next
From: Jerry Sievers
Date:
Subject: Re: dumping table contents in a sensible order