Re: Not In Foreign Key Constraint

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Not In Foreign Key Constraint
Date: 2013-09-18 23:36:27
Message-ID: 1379547387639-5771546.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Misa Simic wrote
> I guess that rule can be achieved with triigers on TableA and TableC - but
> the same is true for FK (and FK constraint is more effective then trigger
> -
> that is why I wonder would it be useful/achievable to create that kind of
> constraint)
>
> Thoughts, ideas?

You create a common "keys in use" table and only insert a record into the
main tables if you can successfully add the desired key to the shared keys
table ( as a unique value ). Setup a normal FK to that table to help
enforce that valid records must exist on the keys table. Not fool-proof but
you only need to worry about insertions - delete from the pk table to remove
the record from the main table and free up the key.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Not-In-Foreign-Key-Constraint-tp5771056p5771546.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Janes 2013-09-19 01:20:00 Freezing without write I/O
Previous Message Vik Fearing 2013-09-18 23:29:00 Re: record identical operator