When to use inherited tables in PostgreSQL?

后端 未结 7 1104
遇见更好的自我
遇见更好的自我 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条回答
  •  天命终不由人
    2020-12-12 12:07

    Main use of inheritance is for partitioning, but sometimes it's useful in other situations. In my database there are many tables differing only in a foreign key. My "abstract class" table "image" contains an "ID" (primary key for it must be in every table) and PostGIS 2.0 raster. Inherited tables such as "site_map" or "artifact_drawing" have a foreign key column ("site_name" text column for "site_map", "artifact_id" integer column for the "artifact_drawing" table etc.) and primary and foreign key constraints; the rest is inherited from the the "image" table. I suspect I might have to add a "description" column to all the image tables in the future, so this might save me quite a lot of work without making real issues (well, the database might run little slower).

    EDIT: another good use: with two-table handling of unregistered users, other RDBMSs have problems with handling the two tables, but in PostgreSQL it is easy - just add ONLY when you are not interrested in data in the inherited "unregistered user" table.

提交回复
热议问题