Peter Eisentraut <peter_e@gmx.net> writes:
> Thinking about SQL assertions (check constraints that are independent of
> one particular table), do you think it would be reasonable to implement
> those on top of constraint triggers? On creation you'd hook up a
> trigger to each of the affected tables. And the trigger function runs
> the respective check expression. Conceptually, this doesn't seem to be
> very far away from foreign key constraints after all.
On further reflection it seems like the major implementation problem
would be to identify "the affected tables". What if the assertion
references views, or user-defined functions that contain queries?
Even an assertion on a table with inheritance children would be a
bit problematic. In principle you could handle the latter case by
propagating copies of the trigger to all the children, but we have
no mechanism for that now.
regards, tom lane