Domains (was Re: int1?) - Mailing list pgsql-general

From Ron Johnson
Subject Domains (was Re: int1?)
Date
Msg-id 1065727737.1234.85.camel@haggis
Whole thread Raw
In response to Re: int1?  (Sean Chittenden <sean@chittenden.org>)
Responses Re: Domains (was Re: int1?)  (Bruno Wolff III <bruno@wolff.to>)
Re: Domains (was Re: int1?)  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-general
On Thu, 2003-10-09 at 12:54, Sean Chittenden wrote:
> > > > Is there any date type that can be used for 0-255 values? Like
> > > > an "int1" or byte column.
> > >
> > > A SMALLINT is two bytes on disk, use "char" instead.  This is a hidden
> >
> > However "char" has some serious deficiencies IIRC, such as the fact
> > that there's no int<->"char" casts and it's standard I/O format is
> > characters.  You can use ascii and chr to get around some of that,
> > but it's ugly.
>
> *nods* I have explicit casts everywhere when dealing with "char" and
> it's far from being elegant or clean.
>
> >
> > > goodie in PostgreSQL and one that I wish was exposed via a more
> > > conventional syntax (*hint hint*).
> >
> > If we were going to do that I think we'd be better off making a new
> > type and leaving "char" alone.
> >
>
> You won't hear any disagreements from me on this one.  I've
> sufficiently abused "char" as a 1 byte storage field and would love to
> see an int1 or tinyint datatype added to cover this situation.  -sc

http://www.postgresql.org/docs/7.3/static/sql-createdomain.html
  CREATE DOMAIN domainname [AS] data_type
       [ DEFAULT default_expr ]
       [ constraint [, ... ] ]

   where constraint is:

   [ CONSTRAINT constraint_name ]
   { NOT NULL | NULL }

test1=# create domain d_tinyint as smallint constraint chk_tinyint CHECK (smallint between 0 and 255);
ERROR:  DefineDomain: CHECK Constraints not supported

So, how would I create a domain that limits a smallint?

--
-----------------------------------------------------------------
Ron Johnson, Jr. ron.l.johnson@cox.net
Jefferson, LA USA

"You can either have software quality or you can have pointer
arithmetic, but you cannot have both at the same time."
Bertrand Meyer


pgsql-general by date:

Previous
From: CSN
Date:
Subject: Re: autoupdate sequences after copy
Next
From: "scott.marlowe"
Date:
Subject: Re: Response from MySql AB (Re: Humor me: Postgresql vs.