Another solution would be to create an
IMMUTABLE function
doing the check and use that in aCHECK
constraint [1].
Why do you need an FK constraint? Why can you not use a data modification trigger?
Placing the subquery within a mis-defined immutable function so PostgreSQL is oblivious to it doesn't do anything to overcome the fact that the system is not designed to have check constraints with subqueries. You are likely to get burned - commonly during backup restoration but there is no guarantees as to why might happen.
David J.