![]() ![]() ![]() Given the sample data from the PostgreSQL tutorial (see Section 2.1), this returns: For example, the following query finds the names of all cities, including state capitals, that are located at an elevation over 500 feet: In PostgreSQL, a table can inherit from zero or more other tables, and a query can reference either all rows of a table or all rows of a table plus all of its descendant tables. State capitals also have an extra column, state, that shows their state. In this case, the capitals table inherits all the columns of its parent table, cities. We define the capitals table so that it inherits from cities: However, what happens when we want to ask for data about a city, regardless of whether it is a capital or not? The inheritance feature can help to resolve this problem. This can be done by creating two tables, one for state capitals and one for cities that are not capitals. We want to be able to quickly retrieve the capital city for any particular state. Each state has many cities, but only one capital. Let's start with an example: suppose we are trying to build a data model for cities. ![]() (SQL:1999 and later define a type inheritance feature, which differs in many respects from the features described here.) PostgreSQL implements table inheritance, which can be a useful tool for database designers. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |