Обсуждение: Alias to a type

Поиск
Список
Период
Сортировка

Alias to a type

От
Veikko Mäkinen
Дата:
Hey,

Is it possible to create a new type as an alias to a pre-defined type? I 
use "USERID varchar(20)" in almost every table I have I'd like to make 
an alias for that type eg.

<pseudo-sql>  create type myschema.useridtype as varchar(20);
</pseudo-sql>

I might have to alter the type some day and this way I'd have to just 
re-define the alias. Can this be achieved by creating a new type with 
CREATE TYPE? What are the input/output functions in the CREATE TYPE 
definition?

Thanks.


-veikko



Re: Alias to a type

От
Achilleus Mantzios
Дата:
O Veikko Mδkinen έγραψε στις Jun 22, 2005 :

> Hey,
> 
> Is it possible to create a new type as an alias to a pre-defined type? I 
> use "USERID varchar(20)" in almost every table I have I'd like to make 
> an alias for that type eg.
> 
> <pseudo-sql>
>    create type myschema.useridtype as varchar(20);
> </pseudo-sql>
> 

Try something like

CREATE DOMAIN my_integer AS INTEGER;

> I might have to alter the type some day and this way I'd have to just 
> re-define the alias. Can this be achieved by creating a new type with 
> CREATE TYPE? What are the input/output functions in the CREATE TYPE 
> definition?
> 
> Thanks.
> 
> 
> -veikko
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 

-- 
-Achilleus



Re: Alias to a type

От
Sean Davis
Дата:
On Jun 22, 2005, at 7:42 AM, Achilleus Mantzios wrote:

> O Veikko Mδkinen έγραψε στις Jun 22, 2005 :
>
>> Hey,
>>
>> Is it possible to create a new type as an alias to a pre-defined
>> type? I
>> use "USERID varchar(20)" in almost every table I have I'd like to make
>> an alias for that type eg.
>>
>> <pseudo-sql>
>>    create type myschema.useridtype as varchar(20);
>> </pseudo-sql>
>>
>
> Try something like
>
> CREATE DOMAIN my_integer AS INTEGER;

Just for my own edification, does creating a "simple" domain like this
then require a whole set of functions for indexing, etc., like other
more complex user-defined types, or will postgres "do the right thing"?

Thanks,
Sean



Re: Alias to a type

От
Richard Huxton
Дата:
Veikko Mäkinen wrote:
> Hey,
>
> Is it possible to create a new type as an alias to a pre-defined type? I
> use "USERID varchar(20)" in almost every table I have I'd like to make
> an alias for that type eg.

CREATE DOMAIN username_string AS varchar(20);

Test it with your client applications though, make sure they cope. Some
don't cope well with user-defined types.
--   Richard Huxton  Archonet Ltd



Re: Alias to a type

От
Bruno Wolff III
Дата:
On Wed, Jun 22, 2005 at 08:04:39 -0400, Sean Davis <sdavis2@mail.nih.gov> wrote:
> 
> 
> Just for my own edification, does creating a "simple" domain like this 
> then require a whole set of functions for indexing, etc., like other 
> more complex user-defined types, or will postgres "do the right thing"?

No, the underlying type's class is still used. You don't need to create
new comparison or type conversion functions.


Re: Alias to a type

От
Achilleus Mantzios
Дата:
O Sean Davis έγραψε στις Jun 22, 2005 :

> 
> On Jun 22, 2005, at 7:42 AM, Achilleus Mantzios wrote:
> 
> > O Veikko MΞ΄kinen έγραψΡ στις Jun 22, 2005 :
> >
> >> Hey,
> >>
> >> Is it possible to create a new type as an alias to a pre-defined 
> >> type? I
> >> use "USERID varchar(20)" in almost every table I have I'd like to make
> >> an alias for that type eg.
> >>
> >> <pseudo-sql>
> >>    create type myschema.useridtype as varchar(20);
> >> </pseudo-sql>
> >>
> >
> > Try something like
> >
> > CREATE DOMAIN my_integer AS INTEGER;
> 
> Just for my own edification, does creating a "simple" domain like this 
> then require a whole set of functions for indexing, etc., like other 
> more complex user-defined types, or will postgres "do the right thing"?

In the above example you may safely consider indexing columns
of type my_integer as indexing INTEGERs.

> 
> Thanks,
> Sean
> 
> 

-- 
-Achilleus



Re: Alias to a type

От
Veikko Mäkinen
Дата:
Richard Huxton wrote:
> Veikko Mäkinen wrote:
> 
>> Hey,
>>
>> Is it possible to create a new type as an alias to a pre-defined type? 
>> I use "USERID varchar(20)" in almost every table I have I'd like to 
>> make an alias for that type eg.
> 
> 
> CREATE DOMAIN username_string AS varchar(20);
> 
> Test it with your client applications though, make sure they cope. Some 
> don't cope well with user-defined types.


Splendid, thank you all :) I'm quite sure loosely typed PHP can cope 
with my user-defined types ;)

But now I need a better modeling tool because Azzurri Clay 1.1 (Eclipse 
plug-in) doesn't let me define new types... Any suggestions? SQL DDL 
generation is the only demand I really have.


-veikko



Re: Alias to a type

От
KÖPFERL Robert
Дата:
Keep in mind, though. Using a DOMAIN in some definition 'seals' the domain.
Yo can't change the domain unless you drop all dependent objects

|-----Original Message-----
|From: Veikko Mäkinen [mailto:veikko.makinen@ecom.fi]
|Sent: Mittwoch, 22. Juni 2005 15:14
|To: pgsql-sql@postgresql.org
|Subject: Re: [SQL] Alias to a type
|
|
|Richard Huxton wrote:
|> Veikko Mäkinen wrote:
|>
|>> Hey,
|>>
|>> Is it possible to create a new type as an alias to a
|pre-defined type?
|>> I use "USERID varchar(20)" in almost every table I have I'd like to
|>> make an alias for that type eg.
|>
|>
|> CREATE DOMAIN username_string AS varchar(20);
|>
|> Test it with your client applications though, make sure they
|cope. Some
|> don't cope well with user-defined types.
|
|
|Splendid, thank you all :) I'm quite sure loosely typed PHP can cope
|with my user-defined types ;)
|
|But now I need a better modeling tool because Azzurri Clay 1.1
|(Eclipse
|plug-in) doesn't let me define new types... Any suggestions? SQL DDL
|generation is the only demand I really have.
|
|
|-veikko
|
|
|---------------------------(end of
|broadcast)---------------------------
|TIP 3: if posting/reading through Usenet, please send an appropriate
|       subscribe-nomail command to majordomo@postgresql.org so
|that your
|       message can get through to the mailing list cleanly
|