Re: Is CREATE TYPE an alias for CREATE DOMAIN?

Lists: pgsql-general
From: John Dean <john(at)totalrekall(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Is CREATE TYPE an alias for CREATE DOMAIN?
Date: 2005-12-22 07:31:04
Message-ID: 6.1.2.0.2.20051222072717.027fe700@mail.totalrekall.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi

Could somebody please tell me if CREATE TYPE is equivalent to CREATE
DOMAIN? If not is there a work around

---

Regards
John Dean,
co-author of Rekall,
the only alternative
to MS Access


From: Richard Huxton <dev(at)archonet(dot)com>
To: John Dean <john(at)totalrekall(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is CREATE TYPE an alias for CREATE DOMAIN?
Date: 2005-12-22 09:36:52
Message-ID: 43AA73B4.3020702@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

John Dean wrote:
> Hi
>
> Could somebody please tell me if CREATE TYPE is equivalent to CREATE
> DOMAIN? If not is there a work around

What do you mean by "equivalent"? You wouldn't use them in the same way,
and I'm not sure what a work-around would consist of.

What are you trying to do?

--
Richard Huxton
Archonet Ltd


From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: John Dean <john(at)totalrekall(dot)co(dot)uk>, pgsql-general(at)postgresql(dot)org
Subject: Re: Is CREATE TYPE an alias for CREATE DOMAIN?
Date: 2005-12-22 15:52:05
Message-ID: 20051222155205.GX72143@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Thu, Dec 22, 2005 at 09:36:52AM +0000, Richard Huxton wrote:
> John Dean wrote:
> >Hi
> >
> >Could somebody please tell me if CREATE TYPE is equivalent to CREATE
> >DOMAIN? If not is there a work around
>
> What do you mean by "equivalent"? You wouldn't use them in the same way,
> and I'm not sure what a work-around would consist of.
>
> What are you trying to do?

Some (most?) database's idea of 'creating a type' is actually what we
consider creating a domain, since many databases don't support users
adding arbitrary types to the system. I suspect this user is trying to
port some code over...
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
Cc: Richard Huxton <dev(at)archonet(dot)com>, John Dean <john(at)totalrekall(dot)co(dot)uk>, pgsql-general(at)postgresql(dot)org
Subject: Re: Is CREATE TYPE an alias for CREATE DOMAIN?
Date: 2005-12-22 16:13:30
Message-ID: 200512221613.jBMGDUx09493@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Jim C. Nasby wrote:
> On Thu, Dec 22, 2005 at 09:36:52AM +0000, Richard Huxton wrote:
> > John Dean wrote:
> > >Hi
> > >
> > >Could somebody please tell me if CREATE TYPE is equivalent to CREATE
> > >DOMAIN? If not is there a work around
> >
> > What do you mean by "equivalent"? You wouldn't use them in the same way,
> > and I'm not sure what a work-around would consist of.
> >
> > What are you trying to do?
>
> Some (most?) database's idea of 'creating a type' is actually what we
> consider creating a domain, since many databases don't support users
> adding arbitrary types to the system. I suspect this user is trying to
> port some code over...

CREATE DOMAIN builds on an existing data type and adds additional
characteristics and checks to the type. It is sort of like a macro for
types.

CREATE TYPE creates a new data type, independent of existing data types,
and usually requires C code and a shared object file to load into the
database.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is CREATE TYPE an alias for CREATE DOMAIN?
Date: 2005-12-22 16:16:16
Message-ID: 200512221716.16486.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Jim C. Nasby wrote:
> Some (most?) database's idea of 'creating a type' is actually what we
> consider creating a domain,

Which databases do such a thing?

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Is CREATE TYPE an alias for CREATE DOMAIN?
Date: 2005-12-28 17:09:25
Message-ID: 20051228170925.GD72143@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Thu, Dec 22, 2005 at 05:16:16PM +0100, Peter Eisentraut wrote:
> Jim C. Nasby wrote:
> > Some (most?) database's idea of 'creating a type' is actually what we
> > consider creating a domain,
>
> Which databases do such a thing?

IIRC, Oracle, DB2, Sybase and MSSQL, though my memory's rusty... and I
should have mentioned that most are just creating an alias for a type
name, so you can't add stuff like constraints to the new type.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461


From: John Dean <john(at)totalrekall(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Is CREATE TYPE an alias for CREATE DOMAIN?
Date: 2005-12-29 13:08:37
Message-ID: 6.1.2.0.2.20051229120617.0281aef0@mail.totalrekall.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi Jim

I have checked through the docs for:-
1. Interbase/Firebird
2. Sybase/MS SQL Server
3. Oracle
4. DB2
5. PostgreSQL
BTW I didn't bother to check the MySQL docs because I do not consider MySQL
to be a RDBMS

It seems that only Interbase/Firebird and PostgreSQL supports the CREATE
DOMAIN syntax. DB2 includes something similar - CREATE DISTINCTIVE TYPE.
But it doesn't allow a constraint to be included

At 17:09 28/12/2005, you wrote:
>On Thu, Dec 22, 2005 at 05:16:16PM +0100, Peter Eisentraut wrote:
> > Jim C. Nasby wrote:
> > > Some (most?) database's idea of 'creating a type' is actually what we
> > > consider creating a domain,
> >
> > Which databases do such a thing?
>
>IIRC, Oracle, DB2, Sybase and MSSQL, though my memory's rusty... and I
>should have mentioned that most are just creating an alias for a type
>name, so you can't add stuff like constraints to the new type.

Those RDBMS which do support the CREATE DOMAIN syntax allows the inclusion
of a named constraint and/or a CHECK constrain
Below is a copy of the first few lines from the PostgreSQL SQL Language
Reference

CREATE DOMAIN

Name

CREATE DOMAIN -- define a new domain

Synopsis

CREATE DOMAIN name [AS] data_type
[ DEFAULT expression ]
[ constraint [ ... ] ]

where constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL | NULL | CHECK (expression) }

Description

CREATE DOMAIN creates a new data domain. The user who defines a domain
becomes its owner.

If a schema name is given (for example, CREATE DOMAIN myschema.mydomain
...) then the domain is created in the specified schema. Otherwise it is
created in the current schema. The domain name must be unique among the
types and domains existing in its schema.

Domains are useful for abstracting common fields between tables into a
single location for maintenance. For example, an email address column may
be used in several tables, all with the same properties. Define a domain
and use that rather than setting up each table's constraints individually.

Sybase/MS SQL Server makes use of the store procedure - sp_addtype, which
is similar to DB2's CREATE DISTINCTIVE TYPE
Oracle uses a variation on the CREATE TYPE syntax. But just like Sybase, MS
SQL Server and DB2 it does not accept a named constraint or CHECK clause

>--
>Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
>Pervasive Software http://pervasive.com work: 512-231-6117
>vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

---

Regards
John Dean,
co-author of Rekall,
the only alternative
to MS Access