0

I need dump database into 2 sql files : ddl script and dml script.

I used pgadmin's gui, clicked on backup and check only Only schema option to create ddl. Next I did same operation, but I clicked Only data to create dml.

Problem is with insert orders and import crashed on FK constraint.

For instance I have table Foo(id, foo_parent_id, ...) and insert are in this order:

insert into foo values(1, 3);
insert into foo values(2, 3);
insert into foo values(3, null);

during file execution it crashed on first insert because parent with id 3 not exists. Is possible solve it? I executed these files in docker postgres container. Thank you.

Denis Stephanov
  • 4,563
  • 24
  • 78
  • 174

1 Answers1

0

You can alter your foreign key constraint as deferrable initially deferred or deferrable and explicitly defer it before you start inserting data.

This way foreign key relationships would be checked at the end of the transaction (which would imply that you will need your inserts to happen in the transactions, if they are not already).

ADEpt
  • 5,504
  • 1
  • 25
  • 32