Re: How Can I use OO concepts?

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: flavio(at)gral(dot)org(dot)br
Cc: postgresql- <pgsql-novice(at)postgresql(dot)org>
Subject: Re: How Can I use OO concepts?
Date: 2005-11-23 17:09:20
Message-ID: 1132765760.14742.86.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Wed, 2005-11-23 at 16:47 +0000, flavio(at)gral(dot)org(dot)br wrote:
> 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.
...
>
> 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);

The mixed-case table names are a bad idea. They are automatically
folded to lower-case unless double-quoted; it just causes confusion.

You have already created tables, so the next three lines are not needed:
> CREATE TABLE employees AS SELECT * FROM Employee;
> CREATE TABLE programmers AS SELECT * FROM Programmer;
> CREATE TABLE representatives AS SELECT * FROM Representative;
(you could create views, but why bother?)

> 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');

Insert directly into the tables you created first.

> ORACLE Query Output
> SELECT e.Name FROM employees e;
> Would be:
>
> Name
> --------------------
> Sylvia Karsen

In PostgreSQL, that returns all records in the hierarchy.

This is how it goes in PostgreSQL:

junk=# CREATE TABLE Employee (
junk(# Name VARCHAR(20),
junk(# Salary NUMERIC(6,2)
junk(# );
CREATE TABLE
junk=# CREATE TABLE Programmer (
junk(# Language VARCHAR(12),
junk(# Project VARCHAR(30)
junk(# )INHERITS (Employee);
CREATE TABLE
junk=# CREATE TABLE Representative (
junk(# Region VARCHAR(30)
junk(# ) INHERITS (Employee);
CREATE TABLE
junk=# INSERT INTO employee VALUES ('Sylvia Karsen', 3000.00);
INSERT 0 1
junk=# INSERT INTO programmer VALUES ('William Helprin', 400.00, 'C++',
'Seestorm');
INSERT 0 1
junk=# INSERT INTO representative VALUES ('Akiko Yokomoto', 500.00,
'Asia');
INSERT 0 1
junk=# SELECT e.Name FROM employee e;
name
-----------------
Sylvia Karsen
William Helprin
Akiko Yokomoto
(3 rows)

junk=# SELECT e.Name FROM ONLY employee e;
name
---------------
Sylvia Karsen
(1 row)

junk=#

--
Oliver Elphick olly(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
Do you want to know God? http://www.lfix.co.uk/knowing_god.html

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Chris Browne 2005-11-23 17:24:50 Re: How Can I use OO concepts?
Previous Message flavio 2005-11-23 16:47:17 How Can I use OO concepts?