![]() ![]() This in effect partitions the data, improving the speed to retrieve data. Inheritance splits data into smaller tables that inherit some of the parent's fields. We now have a copy of the main parent blueprint with a new "patio" item, without creating a duplicated blueprint. Instead of recreating the entire blueprint, we can create a new "child" table that inherits the parent table. ![]() This new blueprint is identical to our existing one, but with a new room. Now let's say we wanted to add a blueprint for a home with a patio. We can create a parent table to store these shared attributes. There are some things that we know every home will have such as: bedrooms, bathrooms, and kitchens. Let's take a database that's used to store blueprints for different types of homes. ![]() Inheritance in PostgreSQL allows you to create a child table based on another table, and the child table will include all of the columns in the parent table. It is a process for deriving one object from another object so that they have shared properties. Inheritance is one of the main principles of object-oriented programming. To follow along with the examples in this article, try Arctype's free SQL editor to quickly connect to a Postgres database: Try Arctype today What is Table Inheritance in Postgres? In this article, I’ll cover how inheritance works in Postgres and provide some examples of when to use inheritance. Table inheritance is a less commonly used Postgres feature, but it has the power to save time with both data retrieval and database management. ![]()
0 Comments
Leave a Reply. |