Re: functions allowed in CHECK constraints

"David G. Johnston" <[email protected]>
Newsgroups gmane.comp.db.postgresql.sql
Message-ID <CAKFQuwY6=rJ0J+b9b4VQ=JkJUTdv95N9bmUE9MZojzdetJM3Ow@mail.gmail.com>
On Fri, Feb 9, 2018 at 1:37 AM, Achilleas Mantzios <
[email protected]> wrote:

>
> So, what's the point in forbidding the use of subselects if one can use
> functions? And OTOH if effectively doing so is bad for some reason, why let
> it happen with a function?


Short answer, the system treats the function as a black-box and doesn't
know that you've used it to circumvent its prohibition on subselects.  The
prohibition still is in place though.  If you use a function you are
expected to ensure you do not violate any of the restrictions yourself.

The reason it is bad is because the query is only run at row insertion time
- and if the external data that the subquery references changes the check
constraint can become invalidated.  If that happens at minimum a
dump/restore will fail.

David J.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.