6 Apr 2002 17:27
Re: [GENERAL] inherited columns as foreign keys WAS "no subject"
Michael Adler <adler <at> glimpser.org>
2002-04-06 15:27:37 GMT
2002-04-06 15:27:37 GMT
On Fri, 5 Apr 2002, Stephan Szabo wrote: > > I get a "referential integrity violation", but the referenced key *does* > > exist in the referenced table. > > > > I don't think that it's important, but the table "object" is inherited by > > other tables. > > In fact it may certainly be... References constraints do not inherit > to children currently. The constraint selects from only the named table > (do a select * from ONLY object where id=...) and I'd guess that the row > is actually in one of the children. I think the solution is to create a unique index on the child table so that you can reference the inherited column. In that "gee, it would be nice" category of suggestions, I'd like to see more documentation on inheritance, it's limitations and suggested workarounds. This has probably all been said before.. The interactive docs on inheritance suggest one workaround for inherited columns as foreign keys: use a "CHECK" constraint with a custom function instead of REFERENCES constraint. Without much investigation, it seems like a better idea to create a unique index on the child table and REFERENCE that. This seems simpler to setup and affords more integrity features. I haven't really tried it, though. The other limitation that I didn't find in the main docs is that child tables don't inherit triggers. You have to add a trigger for each child(Continue reading)
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo <at> postgresql.org
. "SELECT * FROM INFORMATION_SCHEMA.TABLES" doesn't seem
to have any great advantage over either "\d" or whatever the equivalent
MySQL SHOW command is...
regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
RSS Feed