I am currently looking for a way in PostgreSQL where I can, for a given table, limit the number of valid foreign keys available by defining a condition.
So the scenario is like this
https://dbfiddle.uk/?rdbms=postgres_11&fiddle=4dbe279906dc881598b7e72093534ce7
A, B, C All represent different entities, and each specific entry is listed in the x_entry table.
The tables A, B, C all represents versions of a given entry, an in what time span they are valid.
I want to ensure that
the table A always have foreign keys to B and C
where the condition A.B.C == A.C for the timespan A.
As seen here
The condition for Ainit for the range 2000-3000 is violated since, binit in the time range 2100-3000 has a foreign key to cinot
where ainit changes it foreign key from cinit to cinat violating the condition of A.B.C == A.C
But how do i set up such a conditional limit, that prevent a certain condition like this is not being violated for foreign keys. ? and is it even possible?