Re: Constraint documentation - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Constraint documentation
Date
Msg-id 0b1ad66c-6c2c-a5a6-f180-9d4c86a1e305@2ndquadrant.com
Whole thread Raw
In response to Re: Constraint documentation  (Lætitia Avrot <laetitia.avrot@gmail.com>)
Responses Re: Constraint documentation
Re: Constraint documentation
List pgsql-hackers
On 6/26/18 09:49, Lætitia Avrot wrote:
> +   <note>
> +    <para>
> +     Check constraints are not designed to enforce business rules across tables.
> +     Avoid using check constraints with a function accessing other tables and
> +     use <xref linkend="triggers"/> instead. Although PostgreSQL won't prevent you
> +     from doing so, beware that dumps generated by <application>pg_dump</application>
> +     or <application>pg_dumpall</application> may be hard
> +     to restore because of such checks, as the underlying dependencies are not
> +     taken into account.
> +    </para>
> +   </note>

In a way, I think this is attacking the wrong problem.  It is saying
that you should use triggers instead of check constraints in certain
circumstances.  But triggers are also used as an implementation detail
of constraints.  While it currently doesn't exist, a deferrable check
constraint would probably be implemented as a trigger.  It's not the
triggerness that fixes this problem.  The problem is more generally that
if a function uses a table, then pg_dump can't know about the ordering.
It happens to work for triggers because triggers are dumped after all
tables, as a performance optimization, and we could very well dump check
constraints differently as well.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


pgsql-hackers by date:

Previous
From: "Andrey V. Lepikhov"
Date:
Subject: Re: [WIP] [B-Tree] Retail IndexTuple deletion
Next
From: Amit Langote
Date:
Subject: Re: postgresql_fdw doesn't handle defaults correctly