PostgreSQL Tutorial for Absolute Beginners [Administration]
About Lesson

PostgreSQL Features

Object Relational Database Management System:

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.,

  1. Function overloading:

Function with single argument

CREATE OR REPLACE FUNCTION sum_fn(sum INTEGER)
  RETURNS INTEGER AS $$
DECLARE
   result INTEGER;
BEGIN
  result=sum+10;
  RETURN result;
END; $$ 
LANGUAGE plpgsql;
postgres=# select sum_fn(21); 
sum_fn 
-------- 
31 
1 row)

Function with two argument

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,21);
sum_fn
--------
441
(1 row)

      2. 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);

postgres=# select x,
postgres-#        1 + x as "1+",
postgres-#        '127.0.0.1'::inet + x as "ip address",
postgres-#        date 'today' + x as date
postgres-#   from (values (0), (1), (2), (3)) as t(x);
 x | 1+ | ip address |    date
---+----+------------+------------
 0 |  1 | 127.0.0.1  | 2021-07-10
 1 |  2 | 127.0.0.2  | 2021-07-11
 2 |  3 | 127.0.0.3  | 2021-07-12
 3 |  4 | 127.0.0.4  | 2021-07-13
(4 rows)

postgres=#

Here, the operator(+), is overloaded based on the database like integer, inet and date etc., further discussion is beyond the scope of this material, but you can always go thru the source code on how operator overloading is carried out in PostgreSQL.