2

Recently on a testing infrastructure, to restore multiple tables (via copy command) I dropped all the foreign keys. I have restored this database schema dump into a different database before dropping the FK.

Is there any way that I can generate the create FK from information_schema or pg_constraint?

I tried to get it from a dump file, but the create table statement itself having the FK (not an Alter table statement).

Any suggestions?

Laurenz Albe
62.1k4 gold badges57 silver badges93 bronze badges
asked Jul 6, 2020 at 6:52

1 Answer 1

0

I think you are looking for pg_constraint_def, like in the following example:

SELECT pg_get_constraintdef(oid)
FROM pg_constraint
WHERE conname = 'child_accountid_itemid_fkey';
answered Jul 6, 2020 at 7:16
1
  • I think it gives a better idea, let me try. Commented Jul 6, 2020 at 7:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.