Re: Doubts about FK

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "Rafael Domiciano" <rafael(dot)domiciano(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Doubts about FK
Date: 2008-09-18 19:47:52
Message-ID: dcc563d10809181247t47bac7d7g40c2ebdefe0c0168@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Sep 18, 2008 at 5:49 AM, Rafael Domiciano
<rafael(dot)domiciano(at)gmail(dot)com> wrote:
> 2008/9/12 Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
>>
>> On Fri, Sep 12, 2008 at 12:14 PM, Rafael Domiciano
>> <rafael(dot)domiciano(at)gmail(dot)com> wrote:
>> > Hi there,
>> >
>> > In my DB I have a couple of FK, so the change of referenced columns is a
>> > quite complicated.
>> > Today, I DISABLE TRIGGER ALL on the tables envolved and then ENABLE
>> > TRIGGER
>> > ALL to back them.
>> > Is there a better way to do that?
>>
>> Depends. Are other people connected to the server when you do it?
>> disable trigger disables the triggers for everybody, not just you if I
>> remember correctly. If other folks are using the db, then they can
>> insert bad data during that period.
>
> I do it in a transaction, so there's no problem about the other folks...!

Wow, I just tested this in 8.3 an the other transactions block waiting
for the one running the alter table to commit or rollback. Cool...

>> > I read something about SET CONSTRAINTS ALL DEFFERED, but I don't know
>> > how to
>> > use it.
>>
>> the constraints have to created as deferrable to do that. then, in a
>> transaction, you can do something like:
>
> Can I turn my FK into deferrable FK only in that transaction?

You have to drop and recreate your constraints to make them deferrable.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joe 2008-09-19 00:48:58 ORDER BY collation order
Previous Message Tom Lane 2008-09-18 14:06:02 Re: inserting boolean values in dynamic queries