Search code examples
postgresqlordbms

What does PostgreSQL to be ORDBMS mean?


Query has not much helped.

As mentioned here, PostgreSQL is ORDBMS.

here, it explains PostgreSQL being RDBMS.


What does it mean that PostgreSQL is an ORDBMS? Is it about supporting user defined datatypes?


Solution

  • An ORDBMS is primarily a relational database that supports some object oriented features.

    PostgreSQL or Postgres (not PostGres) supports table inheritance and function overloading. Both are features usually attributed to object oriented languages.

    One of the situations where the object-oriented approach is visible is the fact that for each table there is a corresponding data type created. So a table is essentially a set of "instances" of a specific type.

    You can even explicitly define a table like that:

    create type person_type as (id integer, firstname text, lastname text);
    create table person of person_type;
    

    Type inheritance is only supported for table types, not for base types:

    create table person (id integer, firstname text, lastname text);
    create table person_with_dob
    ( 
       dob date
    ) inherits (person);
    

    This is however not fully object oriented because the type definition lacks the ability to defined methods on the type (=class) including method visibility. The closest thing to a type method is a function with that type as the parameter:

    create table person (id integer, firstname text, lastname text);
    
    create function fullname(p_row person) returns text
    as
    $$
      select concat_ws(' ', p_row.firstname, p_row.lastname);
    $$ 
    language sql;
    
    insert into person (id, firstname, lastname) values (42, 'Arthur', 'Dent');
    

    Now you can run:

    select p.fullname
    from person p;
    

    and it returns:

    fullname   
    -----------
    Arthur Dent
    

    even though there is no column named fullname in the table person. This behaviour is the closest to a real class/type method found in object oriented languages (but it's not the same thing as it still lacks the ability to define e.g. private methods)


    Creating user defined structured data types is typically also seen as an object oriented feature:

    create type address_type (city text, zipcode text, street text);
    
    create table person
    (
      id integer primary key,
      firstname text,
      lastname text, 
      billing_address address_type, 
      shipping_address address_type
    );
    

    Arrays can also be seen as "sets of objects" however this is not necessarily an object oriented feature.