X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 89573D1BA51 for ; Wed, 20 Aug 2003 12:20:49 -0300 (ADT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 89884-01 for ; Wed, 20 Aug 2003 12:20:39 -0300 (ADT) Received: from news.hub.org (unknown [64.117.224.194]) by svr1.postgresql.org (Postfix) with ESMTP id 9385DD1B92B for ; Wed, 20 Aug 2003 12:20:38 -0300 (ADT) Received: from news.hub.org (host-64-117-224-194.altec1.com [64.117.224.194] (may be forged)) by news.hub.org (8.12.9/8.12.9) with ESMTP id h7KFKcek069829 for ; Wed, 20 Aug 2003 15:20:38 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h7KF6gdn065845 for pgsql-sql@postgresql.org; Wed, 20 Aug 2003 15:06:42 GMT From: David Fetter Subject: Re: Inheritance or no inheritance, there is a question X-Newsgroups: comp.databases.postgresql.sql References: <200308182136.39919.josh@agliodbs.com> User-Agent: tin/1.6.0-20030714 ("Vatersay") (UNIX) (Linux/2.4.20-8 (i686)) Message-ID: <-HOdnWKu_705Et6iXTWc-g@speakeasy.net> Date: Wed, 20 Aug 2003 10:11:32 -0500 Lines: 81 X-Complaints-To: abuse@speakeasy.net X-DMCA-Complaints-To: abuse@speakeasy.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/236 X-Sequence-Number: 14852 Josh Berkus wrote: > Vernon, > >> What is the best solution for this DB scheme problem? > > Have you considered not using inheritance? As a relational-SQL geek myself, > I'm not keen on inheritance -- I feel it mucks up the relational model. Not > everyone agrees with me, of course. > > Personally, I'd suggest the following structure: > > Profile A > id Primary Key > detail1 > detail2 > > Profile B > id Primary Key references Profile A ( ID ) > detail 3 > detail 4 > detail 5 > > Profile Languages > id not null references profile A ( ID ) > language id > primary key id, language id > > etc. > > In this way, Profile B is a child table with a 1:0-1 relationship > with Profile A. Multi-value dependancies, like Languages, can be > related to either the people who belong to the B group (and, by > implication, the B group) or the people who belong to the A group > only. > > Want the B group? SELECT A JOIN B > Want the A group only? SELECT A EXCEPT B > > This is the "relational" way to approach the problem. Grewvy! I've been running a system that takes various kinds of payments, some tables of which are below. INSERTs & UPDATEs only happen on the tables that inherit from the payment table. To sum up or otherwise do reports, I SELECT from the payment table. Is there some relational way to do this without ripping my hair out every time I want to do a new query? As some of you know, I don't have much hair left to lose ;) CREATE TABLE payment ( payment_id SERIAL NOT NULL PRIMARY KEY , order_id INTEGER NOT NULL REFERENCES order(order_id) ON DELETE RESTRICT , amount INTEGER NOT NULL -- pennies , payment_date DATE NOT NULL DEFAULT now() ); CREATE TABLE payment_check ( check_no INTEGER NOT NULL , payer_name VARCHAR(255) NOT NULL ) INHERITS (payment); CREATE TABLE payment_money_order ( issuer VARCHAR(255) NOT NULL , mo_num VARCHAR(64) NOT NULL ) INHERITS (payment); CREATE TABLE payment_wire ( payment_wire_desc VARCHAR(255) NOT NULL ) INHERITS (payment); Cheers, D -- David Fetter david@fetter.org http://fetter.org/ phone: +1 510 893 6100 cell: +1 415 235 3778 Fascism should more properly be called corporatism, since it is the merger of state and corporate power. Benito Mussolini