Re: How Can I use OO concepts?

From: Chris Browne <cbbrowne(at)acm(dot)org>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: How Can I use OO concepts?
Date: 2005-11-23 17:24:50
Message-ID: 60y83f46ql.fsf@dba2.int.libertyrms.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

flavio(at)gral(dot)org(dot)br writes:

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

This is the wrong handling of it. You're inheriting from the wrong
tables. There was no need to have pairs of tables for this.

CREATE TABLE Employees (
Name VARCHAR(20),
Salary NUMERIC(6,2)
);
CREATE TABLE Programmers (
Language VARCHAR(12),
Project VARCHAR(30)
)INHERITS (Employees);

CREATE TABLE Representatives (
Region VARCHAR(30)
) INHERITS (Employees);

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

select * from employees;

That has the expected output...

/* cbbrowne(at)[local]/dba2 tqual_test=*/ select * from employees;
name | salary
-----------------+---------
Sylvia Karsen | 3000.00
William Helprin | 400.00
Akiko Yokomoto | 500.00
(3 rows)
--
select 'cbbrowne' || '@' || 'acm.org';
http://cbbrowne.com/info/spiritual.html
"Markets can remain irrational longer than you can remain solvent."
-- J. M. Keynes

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Zouari Fourat 2005-11-23 17:52:06 Linux DB designer tools
Previous Message Oliver Elphick 2005-11-23 17:09:20 Re: How Can I use OO concepts?