When to use inherited tables in PostgreSQL?

后端 未结 7 1122
遇见更好的自我
遇见更好的自我 2020-12-12 11:40

In which situations you should use inherited tables? I tried to use them very briefly and inheritance didn\'t seem like in OOP world.

I thought it worked like this:<

7条回答
  •  猫巷女王i
    2020-12-12 12:17

    Inheritance can be used in an OOP paradigm as long as you do not need to create foreign keys on the parent table. By example, if you have an abstract class vehicle stored in a vehicle table and a table car that inherits from it, all cars will be visible in the vehicle table but a foreign key from a driver table on the vehicle table won't match theses records.

    Inheritance can be also used as a partitionning tool. This is especially usefull when you have tables meant to be growing forever (log tables etc).

提交回复
热议问题