Re: Domains (Was [PERFORM] Views With Unions) - Mailing list pgsql-general

From Ron Johnson
Subject Re: Domains (Was [PERFORM] Views With Unions)
Date
Msg-id 1059861766.24817.68.camel@haggis
Whole thread Raw
In response to Re: Domains (Was [PERFORM] Views With Unions)  (Jochem van Dieten <jochemd@oli.tudelft.nl>)
List 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.l.johnson@cox.net             |
| Jefferson, LA  USA                                              |
|                                                                 |
| "I'm not a vegetarian because I love animals, I'm a vegetarian  |
|  because I hate vegetables!"                                    |
|    unknown                                                      |
+-----------------------------------------------------------------+



pgsql-general by date:

Previous
From: Ron Johnson
Date:
Subject: Re: Inheritance vs child tables (Was Domains)
Next
From: Ron Johnson
Date:
Subject: Re: Inheritance & multiple-value fields