X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id F2B1BD1B500 for ; Tue, 16 Sep 2003 22:09:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 56570-03 for ; Tue, 16 Sep 2003 19:09:21 -0300 (ADT) Received: from news.hub.org (unknown [64.117.224.194]) by svr1.postgresql.org (Postfix) with ESMTP id 13047D1B4F1 for ; Tue, 16 Sep 2003 19:09:18 -0300 (ADT) Received: from news.hub.org (host-64-117-224-194.altec1.com [64.117.224.194] (may be forged)) by news.hub.org (8.12.9/8.12.9) with ESMTP id h8GM9Isn032062 for ; Tue, 16 Sep 2003 22:09:18 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h8GLwVK7030184 for pgsql-sql@postgresql.org; Tue, 16 Sep 2003 21:58:31 GMT From: Christopher Browne X-Newsgroups: comp.databases.postgresql.sql Subject: Re: A simple way to Create type ...? Date: Tue, 16 Sep 2003 17:27:13 -0400 Organization: Hub.Org Networking Services Lines: 41 Message-ID: <60d6e0h1am.fsf@dev6.int.libertyrms.info> References: <20030916210436.81214.qmail@web21409.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.hub.org User-Agent: Gnus/5.1003 (Gnus v5.10.3) XEmacs/21.4 (Rational FORTRAN, linux) Cancel-Lock: sha1:u8hO1VEgyin/MJZo5btwZvYyV8g= To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/143 X-Sequence-Number: 15121 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.