How Can I use OO concepts? - Mailing list pgsql-novice

From flavio@gral.org.br
Subject How Can I use OO concepts?
Date
Msg-id 20051123164717.30956.qmail@webmail2.locasite.com.br
Whole thread Raw
Responses Re: How Can I use OO concepts?  (Oliver Elphick <olly@lfix.co.uk>)
List pgsql-novice
Hi ALL

I´m trying to test OO concepts using postgres. I took an Oracle example, extracted from
http://savtechno.com/ViewOfORDBMS.html
As I know Oracle has more OO mature concepts, and Postgres? Where is OO into PostgreSQL
(weak point in table?)

How can I do the same as Oracle using Postgres? Please correct me.

Oracle OO
---------------------------------------------------
CREATE TYPE Employee AS OBJECT (
  Name      VARCHAR2(20),
  Salary    NUMBER(6,2)
) NOT FINAL;

CREATE TYPE Programmer UNDER Employee (
  Language   VARCHAR2(12),
  Project    VARCHAR2(30)
);
CREATE TYPE Representative UNDER Employee (
  Region    VARCHAR2(30)
);
CREATE TABLE employees OF Employee;
CREATE TABLE programmers OF Programmer;
CREATE TABLE representatives OF Representative;
INSERT INTO employees VALUES (Employee('Sylvia Karsen', 30000.00));
INSERT INTO programmers VALUES (Programmer('William Helprin', 40000.00, 'C++', 'Seestorm'));
INSERT INTO representatives VALUES (Representative('Akiko Yokomoto', 50000.00, 'Asia'));

The "Programmer" and "Representative" subtypes inherit all the attributes from the
"Employee" supertype. A request for "employees" objects of the "Employee" type means also
request for objects of subtypes, namely "programmers" and "representatives". For example,
the result of the following SQL statement:

ORACLE Query Output
SELECT e.Name FROM employees e;
Would be:

Name
--------------------
Sylvia Karsen
William Helprin
Akiko Yokomoto



My PostgreSQL Solution ???? OO??? I think not.

CREATE TABLE Employee (
  Name      VARCHAR(20),
  Salary    NUMERIC(6,2)
);
CREATE TABLE Programmer (
  Language   VARCHAR(12),
  Project    VARCHAR(30)
)INHERITS  (Employee);
CREATE TABLE Representative  (
  Region    VARCHAR(30)
) INHERITS (Employee);

CREATE TABLE employees AS SELECT * FROM Employee;
CREATE TABLE programmers AS SELECT * FROM  Programmer;
CREATE TABLE representatives AS SELECT * FROM  Representative;

INSERT INTO employees  VALUES ('Sylvia Karsen', 3000.00);
INSERT INTO programmers VALUES ('William Helprin', 400.00, 'C++', 'Seestorm');
INSERT INTO representatives VALUES ('Akiko Yokomoto', 500.00, 'Asia');

ORACLE Query Output
SELECT e.Name FROM employees e;
Would be:

Name
--------------------
Sylvia Karsen



pgsql-novice by date:

Previous
From: Charles Bai
Date:
Subject: Re: how to test a PL/pgSQL function using pgAdmin III ?
Next
From: Oliver Elphick
Date:
Subject: Re: How Can I use OO concepts?