Re: resolution order for foreign key actions?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Karl Czajkowski <karlcz(at)isi(dot)edu>, pgsql-general(at)postgresql(dot)org
Subject: Re: resolution order for foreign key actions?
Date: 2016-11-08 20:20:09
Message-ID: 9f09354d-11a3-c824-3c36-083a997e71bf@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11/08/2016 12:08 PM, Karl Czajkowski wrote:
> Hi,
>
> Is there a formal definition for the order in which constraint actions
> (i.e. the ON DELETE or ON UPDATE rules) are applied when there are
> multiple overlapping/relevant constraints?
>
> I have struggled to find an answer in the manual, but my experiments
> suggest that they are interpreted in the order in which the
> constraints were defined and the first rule in this order is applied
> while subsequent rules are ignored. This can be very confusing if one
> rule says CASCADE and another NO ACTION, and you need to understand
> this order of definition to know whether a delete will cascade or
> raise an error.

Can you provide an example?

>
> Is there a definitive way to introspect the informatation_schema or
> pg_catalog to determine which behaviors will effectively apply to a
> given "DELETE FROM ..." or "UPDATE ..." statement?

Just to clear you are talking about FK constraints, correct?

AFAIK they are just a form of trigger and the rules they follow can be
found here:

https://www.postgresql.org/docs/9.5/static/sql-createtrigger.html

"If multiple triggers of the same kind are defined for the same event,
they will be fired in alphabetical order by name."

There is more, so I would read through the whole thing.

>
> Thanks,
>
>
> Karl
>
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message otar shavadze 2016-11-08 20:27:47 Gin indexes on intarray is fast when value in array does not exists, and slow, when value exists
Previous Message David G. Johnston 2016-11-08 20:19:02 Re: Running on Docker, AWS with Data Stored on EBS