Re: Composite types or composite keys?

From: Tony Theodore <tony(dot)theodore(at)gmail(dot)com>
To: Chris Travers <chris(dot)travers(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org general" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Composite types or composite keys?
Date: 2013-11-18 02:57:32
Message-ID: CAD1A9D2-5CA0-4D2E-B6C6-E433D03417AA@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On 15 Nov 2013, at 8:04 pm, Chris Travers <chris(dot)travers(at)gmail(dot)com> wrote:
>
> In general, if you don't know you need composite types, you don't want them. You have basically three options and the way you are doing it is the most typical solution to the problem

The current way is much easier since I discovered the “JOIN ... USING(..)” syntax and I’m tempted to try natural joins.

> Having experience with table inheritance and composite types in tuples, I will say the former has fewer sharp corners than the latter.
>
> Where composite types really work well is where you want to add functions which take the type as input. In essence you can develop some very sophisticated models with them, but you probably would not use them for storage unless you have other considerations in mind.

Thanks for that, I’ve done some reading on inheritance and it looks like I can create an empty parent table that acts like a column definition template. This also automatically creates a type that can be used in functions which sounds like what I’m after. There are also scenarios where “product” is a combination of “level" and “id” (where “level” can be things like brand/category/sku) and I’d like to use the same calculations regardless of where it sits in the hierarchy.

Cheers,

Tony

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Felipe Gasper 2013-11-18 03:00:50 Re: PGSQL: listing db/role and user/role relationships
Previous Message Tom Lane 2013-11-18 02:20:04 Re: What does this error message mean?