5.3 PostgreSQL as an Object Relational Database


In contrast to the purely relational model, PostgreSQL provides object-oriented capabilities as well. However, PostgreSQL is not a pure object database because it can also be used for building relational models that do not use objects and features like inheritance or other object-oriented features.

In this section you will see a brief overview of PostgreSQL's object-oriented features.

5.3.1 Inheritance

Inheritance is a key feature of every object-oriented system. Just as in PHP, objects inherit from each other. However, some significant differences have to be taken into consideration. In general, two kinds of inheritance have to be distinguished.

5.3.1.1 Dynamic Inheritance

Dynamic inheritance means that a class inherits from the parent class every time a new instance of an object is created. In other words: If the parent class changes, all children of a parent class will automatically be affected by it. In the case of PostgreSQL, tables can inherit columns from other tables. If a column in a parent table is renamed, all child tables will automatically inherit the new name. Dynamic inheritance allows the user to build very flexible data structures that can easily be changed.

5.3.1.2 Static Inheritance

The counterpart of dynamic inheritance is static inheritance. In contrast to dynamic inheritance, static inheritance means that a child inherits only once. If the parent is changed, the child will never inherit these changes because the child is completely independent from the parent class.

This concept is used for database clusters. In the case of PostgreSQL, a database cluster is a set of databases. Every time a database is created, it inherits things like data types and system tables from a parent database. If a data type is added to a parent database, the child data type cannot use the data type unless somebody adds it to it manually.

The concept of static inheritance can be seen as a help, not a burden. With the help of static inheritance, it is easily possible to remove certain elements from a child. This is not possible in the dynamic concept because a child will always inherit everything every time. Because static inheritance means that things are only inherited once, it is an easy task to remove components of the child object without having to worry that they will be inherited again.



PHP and PostgreSQL. Advanced Web Programming2002
PHP and PostgreSQL. Advanced Web Programming2002
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 201

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net