Re: unsigned types - Mailing list pgsql-general

From Michael Glaesemann
Subject Re: unsigned types
Date
Msg-id BD0F1C1F-ED1E-45BD-BFD9-3AEE720595AB@myrealbox.com
Whole thread Raw
In response to unsigned types  (jeff sacksteder <jsacksteder@gmail.com>)
List pgsql-general
On Oct 16, 2005, at 5:42 , jeff sacksteder wrote:

> It occurs to me that I don't know how to define unsigned integer
> datatypes. I'm making a schema to describe network packets and I
> need columns to contain values from 0-255, etc.
>
> I can't seem to find any documentation on this. What's the best
> prectice for this situation?

PostgreSQL does not have native unsigned integer datatypes. (For
reasons why, check the archives.) You can use domains or check
constraints to enforce a non-negative constraint. For example:

create table foo (
     foo_id serial not null unique
     , foo_unsigned_int integer not null check (foo_unsigned_int > 0)
);

or

create created domain unsigned_integer
as integer
check (value > 0);

create table bar (
     bar_id serial not null unique
     , bar_unsigned_int unsigned_integer not null
);

Here are doc references:
[check constraints](http://www.postgresql.org/docs/8.0/interactive/
ddl-constraints.html#AEN1936)
[create domain](http://www.postgresql.org/docs/8.0/interactive/sql-
createdomain.html)

Hope this helps.

Michael Glaesemann
grzm myrealbox com




pgsql-general by date:

Previous
From: jeff sacksteder
Date:
Subject: unsigned types
Next
From: Neil Conway
Date:
Subject: Re: unsigned types