pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
A simple way to Create type ...?
6+ messages / 4 participants
[nested] [flat]

* A simple way to Create type ...?
@ 2003-09-16 21:04 ow <oneway_111@yahoo.com>
  2003-09-16 21:14 ` Re: A simple way to Create type ...? ow <oneway_111@yahoo.com>
  2003-09-16 21:27 ` Re: A simple way to Create type ...? Christopher Browne <cbbrowne@acm.org>
  0 siblings, 2 replies; 6+ messages in thread

From: ow @ 2003-09-16 21:04 UTC (permalink / raw)
  To: pgsql-sql

Hi,

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,
  ....
)

Thanks







__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: A simple way to Create type ...?
  2003-09-16 21:04 A simple way to Create type ...? ow <oneway_111@yahoo.com>
@ 2003-09-16 21:14 ` ow <oneway_111@yahoo.com>
  2003-09-16 21:47   ` Re: A simple way to Create type ...? Rod Taylor <rbt@rbt.ca>
  1 sibling, 1 reply; 6+ messages in thread

From: ow @ 2003-09-16 21:14 UTC (permalink / raw)
  To: pgsql-sql

--- ow <oneway_111@yahoo.com> wrote:
> Hi,
[...]
> 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?

I guess, ideally it'd be
  create type AddressType AS varchar(50) ;
but it does not work.

Any ideas? Thanks





__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: A simple way to Create type ...?
  2003-09-16 21:04 A simple way to Create type ...? ow <oneway_111@yahoo.com>
  2003-09-16 21:14 ` Re: A simple way to Create type ...? ow <oneway_111@yahoo.com>
@ 2003-09-16 21:47   ` Rod Taylor <rbt@rbt.ca>
  2003-09-16 22:13     ` Re: A simple way to Create type ...? ow <oneway_111@yahoo.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Rod Taylor @ 2003-09-16 21:47 UTC (permalink / raw)
  To: ow <oneway_111@yahoo.com>; +Cc: pgsql-sql

> I guess, ideally it'd be
>   create type AddressType AS varchar(50) ;
> but it does not work.

Only one keyword off. SQL calls this a domain.

They're limited in 7.3, but much improved (not yet perfect) for 7.4.

http://www.postgresql.org/docs/7.3/interactive/sql-createdomain.html

Attachments:

  signature.asc (application/pgp-signature, 186B) download

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: A simple way to Create type ...?
  2003-09-16 21:04 A simple way to Create type ...? ow <oneway_111@yahoo.com>
  2003-09-16 21:14 ` Re: A simple way to Create type ...? ow <oneway_111@yahoo.com>
  2003-09-16 21:47   ` Re: A simple way to Create type ...? Rod Taylor <rbt@rbt.ca>
@ 2003-09-16 22:13     ` ow <oneway_111@yahoo.com>
  0 siblings, 0 replies; 6+ messages in thread

From: ow @ 2003-09-16 22:13 UTC (permalink / raw)
  To: Rod Taylor <rbt@rbt.ca>; +Cc: pgsql-sql

--- Rod Taylor <rbt@rbt.ca> wrote:
> Only one keyword off. SQL calls this a domain.
> 
> They're limited in 7.3, but much improved (not yet perfect) for 7.4.
> 
> http://www.postgresql.org/docs/7.3/interactive/sql-createdomain.html

Excellent news! Thanks






__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: A simple way to Create type ...?
  2003-09-16 21:04 A simple way to Create type ...? ow <oneway_111@yahoo.com>
@ 2003-09-16 21:27 ` Christopher Browne <cbbrowne@acm.org>
  2003-09-17 02:39   ` Re: A simple way to Create type ...? John DeSoi <jd@icx.net>
  1 sibling, 1 reply; 6+ messages in thread

From: Christopher Browne @ 2003-09-16 21:27 UTC (permalink / raw)
  To: pgsql-sql

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.



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: A simple way to Create type ...?
  2003-09-16 21:04 A simple way to Create type ...? ow <oneway_111@yahoo.com>
  2003-09-16 21:27 ` Re: A simple way to Create type ...? Christopher Browne <cbbrowne@acm.org>
@ 2003-09-17 02:39   ` John DeSoi <jd@icx.net>
  0 siblings, 0 replies; 6+ messages in thread

From: John DeSoi @ 2003-09-17 02:39 UTC (permalink / raw)
  To: pgsql-sql


On Tuesday, September 16, 2003, at 05:27 PM, Christopher Browne wrote:

> What you want instead is CREATE DOMAIN.
>
> flexreg=# create domain addresstype varchar(50);


The problem here is that you can't tell the difference between a 
addresstype column and a varchar(50) column in the row description 
information returned by SELECT. All columns just look like varchar(50). 
It would be nice if there was something as easy as CREATE DOMAIN but 
worked more like CREATE TYPE.

Best,

John DeSoi, Ph.D.




^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2003-09-17 02:39 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-09-16 21:04 A simple way to Create type ...? ow <oneway_111@yahoo.com>
2003-09-16 21:14 ` ow <oneway_111@yahoo.com>
2003-09-16 21:47   ` Rod Taylor <rbt@rbt.ca>
2003-09-16 22:13     ` ow <oneway_111@yahoo.com>
2003-09-16 21:27 ` Christopher Browne <cbbrowne@acm.org>
2003-09-17 02:39   ` John DeSoi <jd@icx.net>

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