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

From Chris Browne
Subject Re: How Can I use OO concepts?
Date
Msg-id 60y83f46ql.fsf@dba2.int.libertyrms.com
Whole thread Raw
In response to How Can I use OO concepts?  (flavio@gral.org.br)
Responses How does PG Inheritance work?  ("Announce" <truthhurts@insightbb.com>)
List pgsql-novice
flavio@gral.org.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@[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

pgsql-novice by date:

Previous
From: Chris Browne
Date:
Subject: Re: Application using PostgreSQL as a back end (experienced
Next
From: John Hedge
Date:
Subject: Linux Format Gambas Easy Database Access!