Re: Not In Foreign Key Constraint - Mailing list pgsql-hackers

From David Johnston
Subject Re: Not In Foreign Key Constraint
Date
Msg-id 1379547387639-5771546.post@n5.nabble.com
Whole thread Raw
In response to Not In Foreign Key Constraint  (Misa Simic <misa.simic@gmail.com>)
Responses Re: Not In Foreign Key Constraint
List 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.



pgsql-hackers by date:

Previous
From: Vik Fearing
Date:
Subject: Re: record identical operator
Next
From: Jeff Janes
Date:
Subject: Freezing without write I/O