pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christopher Browne <cbbrowne@acm.org>
To: pgsql-sql@postgresql.org
Subject: Re: A simple way to Create type ...?
Date: Tue, 16 Sep 2003 17:27:13 -0400
Message-ID: <60d6e0h1am.fsf@dev6.int.libertyrms.info> (raw)
References: <20030916210436.81214.qmail@web21409.mail.yahoo.com>

oneway_111@yahoo.com (ow) writes:
> I had a look at "create type" docs and it seems somewhat complex, involving
> creation of functions and etc. I hope there's a simpler way for the following:
>
> How should one declare a new custom type, say, "AddressType" that corresponds
> internally to "varchar(50)". In other words, all columns that are assigned
> "AddressType" would internally be "varchar(50)".
>
> Example:
> create type AddressType ... -- how to do it in a simple way?
>
> create table ADDRESS
> {
>   address_id      int           not null,
>   street_address1 AdressType    not null,
>   street_address2 AdressType    not null,
>   ....
> )

CREATE TYPE is intended to do something a whole lot more
sophisticated than you want.

What you want instead is CREATE DOMAIN.

flexreg=# create domain addresstype varchar(50);
CREATE DOMAIN
flexreg=# create table address ( address_id integer not null, street1 addresstype not null, street2 addresstype);
CREATE TABLE
flexreg=# \d address
        Table "public.address"
   Column   |    Type     | Modifiers 
------------+-------------+-----------
 address_id | integer     | not null
 street1    | addresstype | not null
 street2    | addresstype | 
-- 
select 'cbbrowne' || '@' || 'cbbrowne.com';
http://www.ntlug.org/~cbbrowne/nonrdbms.html
"Although  Unix is  more reliable,  NT may  become more  reliable with
time"  --   Ron  Redman,  deputy  technical  director   of  the  Fleet
Introduction Division of the Aegis Program Executive Office, US Navy.



view thread (6+ messages)  latest in thread

Message-ID: <60d6e0h1am.fsf@dev6.int.libertyrms.info>
Permalink:  ../60d6e0h1am.fsf@dev6.int.libertyrms.info/
Also on:    postgresql.org/message-id/60d6e0h1am.fsf@dev6.int.libertyrms.info

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: cbbrowne@acm.org
  Subject: Re: A simple way to Create type ...?
  In-Reply-To: <60d6e0h1am.fsf@dev6.int.libertyrms.info>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox