Re: Domains (Was [PERFORM] Views With Unions)

From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: pgsql General List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Domains (Was [PERFORM] Views With Unions)
Date: 2003-08-02 22:02:46
Message-ID: 1059861766.24817.68.camel@haggis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, 2003-08-02 at 11:29, Jochem van Dieten wrote:
> Francisco J Reyes wrote:
> > Are domains user defined types? That they seem to be based on what I see
> > on the docs.
>
> They are similar a bit to user defined types, but there are some
> important differences.
>
> First of all, domains are based on other datatypes, so you would
> have to have an existing datatype that is a sufficiently close match.
> Secondly, domains can be mixed directly with the datatype they
> are based on and other domains that are based on that datatype.
> User defined types require you to first cast them (which in turn
> implies a casting function needs to be defined) to the other/a
> common type before you can mix them.
>
> Overall, I tend to see them more as macro's then as real
> datatypes. Typically I use them to verify that data is properly
> formatted (like the phone number example).

They are also (primarily?) used on other DBMSs to "prove correctness".
Thus, for example, everywhere you see a field of type TXNID_DOM,
you know that it is a "transaction id", no matter what the field
name is.

It's also theoretically possible to make type modifications simpler.
Say you have domain TXNID_DOM of type INTEGER, and you are running
up against the 2,100,000,000 threshold:
ALTER DOMAIN TXNID_DOM BIGINT;

Now, you have 10^9 more transaction ids. Of course, the down side
is that *every* table with a field of type TXNID_DOM is modified,
and that might take a *REALLY*LONG*TIME*...

--
+-----------------------------------------------------------------+
| Ron Johnson, Jr. Home: ron(dot)l(dot)johnson(at)cox(dot)net |
| Jefferson, LA USA |
| |
| "I'm not a vegetarian because I love animals, I'm a vegetarian |
| because I hate vegetables!" |
| unknown |
+-----------------------------------------------------------------+

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2003-08-02 22:09:12 Re: Inheritance & multiple-value fields
Previous Message Ron Johnson 2003-08-02 21:50:33 Re: Inheritance vs child tables (Was Domains)