Re: temporarily disabling foreign keys

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Seb <spluque(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: temporarily disabling foreign keys
Date: 2011-05-10 18:39:08
Message-ID: BANLkTimt_yf4tUbxneHnU6fYrrBzWXF==g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 10, 2011 at 12:12 PM, Seb <spluque(at)gmail(dot)com> wrote:
> Hi,
>
> I'm not sure how best to handle this situation.  The tables in a
> database need to be completely cleared and copy'ed into about every few
> months, as they are updated with new records and corrections from a
> provider.  Because the tables have foreign key constraints with 'ON
> UPDATE CASCADE ON DELETE RESTRICT', it's not possible to DELETE them
> without violating these constraints.  I've been dropping the constraints
> while doing these transactions and then recreating them once everything
> is done, but this has gotten tedious.  Is there some way to "disable"
> the foreign keys and enabling them after the transactions?  Thanks.

Another option is to load the data into temp tables and run updates
from there against the master table. Delete anything that doesn't
match for the rest.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mark 2011-05-10 18:53:54 ts_rank vs ts_rank_cd
Previous Message John R Pierce 2011-05-10 18:34:37 Re: temporarily disabling foreign keys