4 ms·
The table inheritance one is something I wasn't aware of. I can think of so many great uses for it that it makes me kind of weary. There has to be some downsi
by VectorLock 7y ago
The table inheritance one is something I wasn't aware of. I can think of so many great uses for it that it makes me kind of weary. There has to be some downside, its too good.
- jayd16 7y agoIsn't it just sugar for what you would normally do, which is add another table with the new columns and FK into the base table? I assume it adds some protection around type exclusivity, ie a cat row cannot be a dog row, where as you do not have that protection with cat and dog tables that both reference the animal table. Seems nice but usually you actually would prefer composition over inheritance.
- VectorLock 7y agoIt would simplify the reflection of the schema in code I think. Also not having to do a JOIN, or make a FK, or worry about the cardinality of the FK, or worry about ON DELETE CASCADE. It seems like it wraps it up pretty succinctly.
- xienze 7y agoWell, there’s this blurb in the documentation: “Although inheritance is frequently useful, it has not been integrated with unique constraints or foreign keys, which limits its usefulness.”