Re: How Can I use OO concepts? - Mailing list pgsql-novice
From | Oliver Elphick |
---|---|
Subject | Re: How Can I use OO concepts? |
Date | |
Msg-id | 1132765760.14742.86.camel@linda.lfix.co.uk Whole thread Raw |
In response to | How Can I use OO concepts? (flavio@gral.org.br) |
List | pgsql-novice |
On Wed, 2005-11-23 at 16:47 +0000, flavio@gral.org.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@lfix.co.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
pgsql-novice by date: