How Can I use OO concepts?

From: flavio(at)gral(dot)org(dot)br
To: postgresql- <pgsql-novice(at)postgresql(dot)org>
Subject: How Can I use OO concepts?
Date: 2005-11-23 16:47:17
Message-ID: 20051123164717.30956.qmail@webmail2.locasite.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Oliver Elphick 2005-11-23 17:09:20 Re: How Can I use OO concepts?
Previous Message Charles Bai 2005-11-23 16:03:11 Re: how to test a PL/pgSQL function using pgAdmin III ?