Course Content
ACID Properties and Query Processing
0/2
PostgreSQL Replication
0/1
PostgreSQL Upgrade
0/1
PostgreSQL Tutorial for Absolute Beginners [Administration]
About Lesson

PostgreSQL Database is an ORDBMS. An RDBMS that implements object-oriented features such as user-defined types, inheritance, and polymorphism is called an object-relational database management system (ORDBMS).

PostgreSQL implements inheritance between tables (or, if you like, between classes). Functions and operators are polymorphic.

Example.,

Function overloading

Function with a single argument Function with two argument

CREATE OR REPLACE FUNCTION sum_fn(sum INTEGER)
RETURNS INTEGER AS $$
DECLARE
result INTEGER;
BEGIN
result=sum+10;
RETURN result;
END; $$
LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION sum_fn(sum INTEGER,sum2 INTEGER)
RETURNS INTEGER AS $$
DECLARE
result INTEGER;
BEGIN
result=sum*sum2;
RETURN result;
END; $$
LANGUAGE plpgsql;
postgres=# select sum_fn(21);
sum_fn
——–
31
postgres=# select sum_fn(21,21);
sum_fn
——–
441

Operator overloading

select x,
1 + x as “1+”,
‘127.0.0.1’::inet + x as “ip address”,
date ‘today’ + x as date
from (values (0), (1), (2), (3)) as t(x);

Output

x | 1+ | ip address |    date
–+—-+————+————
0 |  1 | 127.0.0.1  | 2020-03-01
1 |  2 | 127.0.0.2  | 2020-03-02
2 |  3 | 127.0.0.3  | 2020-03-03
3 |  4 | 127.0.0.4  | 2020-03-04

(4 rows)

Here, the operator(+), is overloaded based on the value like integer, inet and date etc

Inheritance

PostgreSQL implements inheritance between tables in the following way.

create table logs_q1
(check (created_at >= date ‘2014-01-01’ and created_at <= date ‘2014-03-31’))
inherits (logs);

where logs in the parent table and logs_q1 is the child table.

Everything is Object in PostgreSQL, your table is identified by OID (Object ID), your user, tablespace, schema, everything is Object here.

Hence your PostgreSQL is considered as ODBMS.