Trying to Understand Table Inheritance

From: Keary Suska <hierophant(at)pcisys(dot)net>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Trying to Understand Table Inheritance
Date: 2006-12-06 20:58:10
Message-ID: C19C7CF2.939E%hierophant@pcisys.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a problem I am trying to address and am looking to see if table
inheritance may be the solution.

My problem is this: I have a POS system using basic POS principles--i.e., I
have an "invoice" table, with a one-to-many related "line items" table. Now,
each line item may specify one of certain "types" of products with
differencing management behaviors. These boil down to: merchandise, which is
ordered/shipped once; memberships, which persist and expire at some point;
and subscriptions, which have a certain number of "issues" that are sent on
a periodic basis.

All line items share certain characteristics, such as a product, quantity,
etc., but also have the differing management criteria--such as ship date,
expiration date, and issues sent. My first approach was to have all of this
data in a single table, but that creates a lot of redundant data and forces
"loose" constraints--e.g. that I have to allow NULL expiration dates for
merchandise products.

My thoughts then turned to table inheritance, but I am not sure whether this
addresses the issue or introduce new problems. My thought was that I could
have an "order_item" table with the columns/data shared by all line items,
and then have three tables--merchandise, membership, and subscription--that
inherit from it.

I understand that queries on order_item would include the child table(s)
columns, but my question is that is this approach essentially the same as
just using one table, vis a vis redundant data? If I insert into order_item,
can I only include columns from a single child table, or do I have to
include all children or risk a constraint violation? Or do I have to only
insert into the child table(s) and include the parent's columns? The latter,
from a functional standpoint, would be more difficult, and messy potentially
messy. Of course, maybe I am barking up the wrong tree?

Thanks,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tomi N/A 2006-12-06 20:59:53 Re: Speed of postgres compared to ms sql, is this
Previous Message Scott Marlowe 2006-12-06 20:57:32 Re: cant connect php to postgresql